Home page > OS X Portable Applications > Portable Inkscape OS X source code
Source code index | Portable Inskscape script code:
Shell Script (Release 2.0)
#!/bin/sh
##########################################################################
#
# Portable Inkscape OS X
# $Revision: 2.0
#
# The Contents of this file are made available subject to the terms of
# either of the following licenses
#
# - GNU General Public License Version 2.1
#
# Carlo Gandolfi, Paolo Portabluri, July 2006
#
# GNU General Public License Version 2.1
# =============================================
# Copyright 2006 by:
# Carlo Gandolfi - http://www.freesmug.org
# Paolo Portaluri - http://plus2.it/~paolo/
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public
# License version 2.1, as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
##########################################################################
# Reset PATH
PATH=/bin:/sbin:/usr/bin:/usr/sbin
export PATH
appid=inkscape
userpref="$HOME/.$appid"
p_userbase="$1/Contents/Resources/app"
p_userpref="$p_userbase/$appid"
copy_pref="$p_userbase/CopyPref_Done"
# ========================================================
# quitapp
# Check if local app is open and quit
# ========================================================
function quitapp {
if ps cx | grep '[0-9] '"inkscape-bin"'$' > /dev/null; then
message1="Inkscape is already running on this system. \
Only one copy can be run at a time"
button=`/usr/bin/osascript << EOT
tell application "Finder"
beep
display dialog "$message1" buttons {"Quit"} \
with title "Quit Running Inkscape" with icon caution default button "Quit"
set result to button returned of result
end tell
EOT`
if test "$button" == "Quit"; then # Quit application
exit 0
fi
fi
}
# ========================================================
# repair
# Repair preferences if Portable Application crashed
# ========================================================
function repair {
if [ -L "$userpref" ] ; then
rm -f "$userpref"
fi
if [ -d "$userpref.pabu" ] ; then
rm -rf "$userpref"
recover_asf
fi
}
# ========================================================
# check_p_asf
# Check and create Portable Application Support folders
# ========================================================
function check_p_asf {
if [ ! -d "$p_userpref" ]; then
mkdir -p "$p_userpref"
fi
}
# ========================================================
# copy_local_pref
# Copy local preferences to Portable Application
# ========================================================
function check_asf {
if [ -d "$p_userpref" ]; then
# delete p_userpref if it still exist
rm -Rf "$p_userpref"
else
mkdir -p "$p_userpref"
fi
}
# copy Preferences Folder
function copy_pf {
userprefsize=`du -hc "$userpref" | cut -f1 | tail -1`
message4="Your Inkscape Preferences folder is $userprefsize. \
Copy it to Portable Inkscape?"
button=`/usr/bin/osascript << EOT
tell application "Finder"
beep
display dialog "$message4" buttons {"Copy", "Cancel"} \
with title "Copy Inkscape Preferences Folder" \
with icon note default button "Cancel"
set result to button returned of result
end tell
EOT`
if test "$button" == "Copy"; then
check_asf
cp -R "$userpref" "$p_userpref"
touch -f "$copy_pref";
fi
}
function copy_local_pref {
if [ ! -f "$copy_pref" ] && [ -d "$userpref" ] ; then
message3="Copy the existing Inkscape preferences on this system \
to Portable Inkscape?"
button=`/usr/bin/osascript << EOT
tell application "Finder"
beep
display dialog "$message3" buttons {"Never", "Copy", "Don't Copy"} \
with title "Copy Preferences" \
with icon note default button "Don't Copy"
set result to button returned of result
end tell
EOT`
if test "$button" == "Copy"; then
copy_pf
elif test "$button" == "Never"; then
touch -f "$copy_pref";
fi
fi
}
# ========================================================
# bu/recover asf
# BackUp existing Application Support Folder and restore portable ones
# ========================================================
function bu_asf {
mv "$userpref" "$userpref.pabu"
}
function recover_asf {
mv "$userpref.pabu" "$userpref"
}
function recover_p_asf {
ln -s "$p_userpref" "$userpref"
}
function bu_p_asf {
rm -rf "$userpref"
}
# ========================================================
# fc_cache
# If on tiger, need to update fc-cache if it hasn't been done
# ========================================================
function notrun_fc_cache {
message6="Font caches have not been updated.\nThey can be updated manually by running \
the following:\n sudo /usr/X11R6/bin/fc-cache -f\nOnce you have dealt with this, \
please re-run Inkscape."
button=`/usr/bin/osascript << EOT
tell application "Finder"
beep
display dialog "$message6" buttons {"OK"} \
with title "Font caches have not been updated" \
with icon caution default button "OK"
set result to button returned of result
end tell
EOT`
if test "$button" == "OK"; then
touch $HOME/.inkscape/.fccache ;
bu_p_asf # Backup portable Applicatin Support folder
if [ -d "$userpref.pabu" ] ; then
recover_asf # Restore portable Application Support folder
fi
exit 0
fi
}
function fc_cache_done {
if [ -f ~/.inkscape/.fccache ]; then
message7="Font caches have been updated. Now Inkscape will open."
button=`/usr/bin/osascript << EOT
tell application "Finder"
beep
display dialog "$message7" buttons {"OK"} \
with title "Font caches have been updated." \
with icon note default button "OK"
set result to button returned of result
end tell
EOT`
elif [ ! -f ~/.inkscape/.fccache ]; then
notrun_fc_cache
fi
}
function run_fc_cache {
"$p_userbase/Inkscape_fc-cache.app/Contents/MacOS/Inkscape_fc-cache"
fc_cache_done
}
function ask_run_fc_cache {
message5="A problem occurs on OS X 10.4 where X11 does not always generate the necessar \
fontconfig caches. This can be corrected by running fc-cache as root.\n\nThis can take \
several minutes, with high processor usage. Please do not close Inkscape."
button=`/usr/bin/osascript << EOT
tell application "Finder"
beep
display dialog "$message5" buttons {"Ignore", "Run fc-cache"} \
with title "Font caches may need to be updated" \
with icon caution default button "Run fc-cache"
set result to button returned of result
end tell
EOT`
if test "$button" == "Run fc-cache"; then
run_fc_cache
elif test "$button" == "Ignore"; then
notrun_fc_cache
fi
}
function fc_cache {
VERSION=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 -d'.'`
if [ "$VERSION" -eq "4" ]; then
# We're on tiger. So need to update fc-cache if it hasn't been done
test -f ~/.inkscape/.fccache || ask_run_fc_cache
fi
}
function run_app {
# BASE="`echo "$0" | sed -e 's/\/Contents\/Resources\/script/\//'`"
# cd "$BASE"
# "$CWD/bin/inkscape" "$@"
"$p_userbase/Inkscape.app/Contents/MacOS/Inkscape"
}
function open_p_app {
if [ -d "$userpref" ] ; then
bu_asf # Backup existing Application Support folder
fi
recover_p_asf # Recover portable Applicatin Support folder
fc_cache
run_app # Run application from external drive
bu_p_asf # Backup portable Applicatin Support folder
if [ -d "$userpref.pabu" ] ; then
recover_asf # Restore portable Application Support folder
fi
}
quitapp
repair
check_p_asf
copy_local_pref
open_p_app
exit 0
#!/bin/sh
/usr/X11R6/bin/fc-cache -f
touch $HOME/.inkscape/.fccache
Modified code is also in the file:
r1.0
Portable Inkscape.app/Contents/Resources/bin/inkscape
r2.0<b>
Portable Inkscape.app/Contents/Resources/app/Inkscape.app/Contents/Resources/bin/inkscape
#!/bin/sh
#
# Author: Aaron Voisine <aaron@voisine.org>
# Inkscape Modifications: Michael Wybrow <mjwybrow@users.sourceforge.net>
# Portable Inkscape: Carlo Gandolfi <http://www.freesmug.org>
CWD="`(cd \"\`dirname \\\"$0\\\"\`\"; echo $PWD)`"
TOP="`dirname \"$CWD\"`"
ETC="$TOP/inkscape-etc"
export "DYLD_LIBRARY_PATH=$TOP/lib"
export "PATH=$CWD:$PATH"
export "PANGO_RC_FILE=$ETC/pangorc"
export "FONTCONFIG_PATH=$TOP/etc/fonts"
export "GTK_IM_MODULE_FILE=$ETC/gtk.immodules"
export "GDK_PIXBUF_MODULE_FILE=$ETC/gdk-pixbuf.loaders"
export "GTK_DATA_PREFIX=$TOP"
export "GTK_EXE_PREFIX=$TOP"
export "GNOME_VFS_MODULE_CONFIG_PATH=$TOP/etc/gnome-vfs-2.0/modules"
export "GNOME_VFS_MODULE_PATH=$TOP/lib/gnome-vfs-2.0/modules"
export "INKSCAPE_SHAREDIR=$TOP"
export "INKSCAPE_PLUGINDIR=$TOP/lib/inkscape"
export "INKSCAPE_LOCALEDIR=$TOP/locale"
# TODO: Have to add ".UTF-8" to the LANG since ommiting causes Inkscape
# to crash on startup in locale_from_utf8().
export "LANG=`grep \"\`defaults read .GlobalPreferences AppleCollationOrder \
2>&1\`_\" /usr/share/locale/locale.alias | tail -n1 | sed 's/\./ /' | \
awk '{print $2}'`.UTF-8"
# Handle the case where the directory storing Inkscape has a '#' in the name.
# This '#' needs to be escaped in pango.modules for Pango to work properly.
ESCAPEDTOP=`echo $TOP | sed 's/#/\\\\\\\\#/'`
mkdir -p "$ETC"
sed 's|${HOME}|'"$TOP|g" "$TOP/etc/pango/pangorc" > "$ETC/pangorc"
sed 's|${CWD}|'"$ESCAPEDTOP|g" "$TOP/etc/pango/pango.modules" > "$ETC/pango.modules"
cp -f "$TOP/etc/pango/pangox.aliases" "$ETC"
sed 's|${CWD}|'"$TOP|g" "$TOP/etc/gtk-2.0/gtk.immodules" > "$ETC/gtk.immodules"
sed 's|${CWD}|'"$TOP|g" "$TOP/etc/gtk-2.0/gdk-pixbuf.loaders" \
> "$ETC/gdk-pixbuf.loaders"
exec "$CWD/inkscape-bin" "$@"
Modified code is also in the file:
r1.0
Portable Inkscape.app/Contents/Resources/etc/pango/pangorc
r2.0
Portable Inkscape.app/Contents/Resources/app/Inkscape.app/Contents/Resources/etc/pango/pangorc
[Pango]
ModuleFiles = "${HOME}/inkscape-etc/pango.modules"
[PangoX]
AliasFiles = "${HOME}/inkscape-etc/pangox.aliases"
Source code for the Inkscape here:
Portable Inkscape and Inkscape OS X are packaged using the Platypus script wrapper from http://sveinbjorn.sytes.net/platypus