Portable Check Off source code

Home page > OS X Portable Applications > Portable Check Off source code

Source code index | Portable Check Off script code:

Portable Check Off.app is packaged using the Platypus script wrapper from http://sveinbjorn.sytes.net/platypus


Shell Script (Release 1.0)


Shell Script (Release 2.0)

#!/bin/sh

##########################################################################
#
#   Portable Check Off
#
#   $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, May 2006
#
#   GNU General Public License Version 2.1
#   =============================================
#   Copyright 2006 by:
#      Carlo Gandolfi - http://www.freesmug.org
#      Paolo Portaluri - http://plus2.it/~paolo/
#
#   This library 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 library 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

appurl=com.carpeaqua.checkoff.plist
appid=Check\ Off
userplistbase="Library/Preferences"
userplist="$HOME/$userplistbase/$appurl"

p_userbase="$1/Contents/Resources/app"
p_userplist="$p_userbase/$userplistbase/$appurl"

copy_pref="$p_userbase/CopyPref_Done"

# ========================================================
# quitapp
# Check if local app is open and quit it
# ========================================================

function quitapp {
if ps cx | grep '[0-9] '"$appid"'$' > /dev/null; then
message1="A copy $appid is already running. Do you want to quit the running application and open Portable $appid instead?"
button=`/usr/bin/osascript << EOT
    tell application "Finder"
    beep
    display dialog "$message1" buttons {"Cancel", "Continue"} \
        with title "Qiut Running $appid" with icon caution default button "Continue"
    set result to button returned of result
    end tell
EOT`
if test "$button" == "Continue"; then        # Quit local application
    osascript -e 'tell app "'"$appid"'" to quit'
else                            
    exit 0
fi
fi
}

# ========================================================
# repair
# Repair preferences if Portable Application crashed
# ========================================================

function repair {
    if test -f "$userplist.pabu"; then
message2="Portable $appid has crashed without restoring existing preferences. \
Do you want to restore the original preferences now \
or copy to BackUp folder to manually restore later?"
button=`/usr/bin/osascript << EOT
    tell application "Finder"
    beep
    display dialog "$message2" buttons {"Continue", "Restore", "Copy"} \
with title "Restoring Existing Preferences" \
with icon stop default button "Copy"
    set result to button returned of result
    end tell
EOT`
if test "$button" == "Copy"; then    # Save old preferences in BackUp folder
    rm -rf "$HOME/$appid Pref BackUp/"
    mkdir -p "$HOME/$appid Pref BackUp/$userplistbase"
    mv "$userplist.pabu" "$HOME/$appid Pref BackUp/$userplistbase/$appurl"
elif test "$button" == "Restore"; then    # Restore existing preference
    recover_plist
else
    rm -f "$userplist.pabu"
fi
fi
}

# ========================================================
# check_p_asf
# Check and create Portable Application Support folders
# ========================================================

function check_p_asf {
    if [ ! -d "$p_userbase/$userplistbase" ]; then
        mkdir -p "$p_userbase/$userplistbase"
    fi
}

# ========================================================
# copy_local_pref
# Copy local preferences to Portable Application
# ========================================================

function copy_local_pref {
if [ ! -f "$copy_pref" ] && test -f  "$userplist" ; then
message="Copy the existing $appid preferences on this system to Portable $appid?"
button=`/usr/bin/osascript << EOT
    tell application "Finder"
    beep
    display dialog "$message" 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    
    bu_p_plist
    touch -f "$copy_pref";
elif test "$button" == "Never"; then
    touch -f "$copy_pref"; 
fi
fi
}

# ========================================================
# bu/recover preference
# BackUp existing preference and restore portable ones
# ========================================================

function bu_plist {
    mv "$userplist" "$userplist.pabu"
}

function recover_plist {
    mv "$userplist.pabu" "$userplist"
}

function recover_p_plist {
    cp "$p_userplist" "$userplist"
}

function bu_p_plist {
    cp "$userplist" "$p_userplist"
}

# ========================================================
# run
# Open Portable Application
# ========================================================

function run_app {
    here="`dirname \"$0\"`"
    cd "$here"
    "$here/app/$appid.app/Contents/MacOS/$appid"
}

# ========================================================
# open_p_app
# Run Portable Application script
# ========================================================

function open_p_app {
    if  test -f "$userplist" ; then
        bu_plist        # Backup of existing preference
    fi
    recover_p_plist            # Recover portable preference
    run_app             # Run application from external drive
    bu_p_plist            # Backup portable preference
    if  test -f "$userplist.pabu" ; then
        recover_plist        # Restore existing preference
    else                # Remove portable preference
        rm -f "$userplist"
    fi
}

quitapp
repair
check_p_asf
copy_local_pref
open_p_app

EOF
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License