Portable Apps Lion Patch source code

Home page > OS X Portable Applications > Portable Apps Lion Patch source code

Source code index | PAppsLionPatch script code:


Shell Script (Release 1.0)

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

#!/bin/sh -x

##########################################################################
#
#   PAppsLionPatch - Patch Portable Apps to Lion
#   $Revision: 1.0
#
#   The Contents of this file are made available subject to the terms
#   of the following license
#
#          - GNU General Public License Version 3.0
#
#   Carlo Gandolfi, September 2011
#
#   GNU General Public License Version 3.0
#   ============================================
#   Copyright 2006-2008 by Carlo Gandolfi (cgand@users.sourceforge.net)
#
#   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=PAppsLionPatch

p_userbase="$1/Contents/Resources"

CD="$p_userbase/CocoaDialog.app/Contents/MacOS/CocoaDialog"

appicon="$p_userbase/appIcon.icns"
cautionicon="$p_userbase/${appid}_Caution.icns"

# ========================================================
# CDokmessage
# CocoaDialog Ok/Cancel message box
# $1 "text"
# $2 "informative text"
# $3 "--no-cancel" = don't show a cancel button
# ========================================================

function CDokmessage {
    beep
    "$CD" ok-msgbox  --icon-file "$appicon" \
    --text "$1" --informative-text "$2" "$3"
}

function CDokmessagec {
    beep
    "$CD" ok-msgbox  --icon-file "$cautionicon" \
    --text "$1" --informative-text "$2" "$3"
}

function beep {
    /usr/bin/osascript << EOT
    tell application "Finder"
    beep
    end tell
EOT
}

# ========================================================
# bsd_command_check
# Check that the required BSD command are installed
# ========================================================

function command_check_msg {
message1="One or more *BSD commands* to run Portable $appid were not found on \
this machine. You must install the BSD Subsystem package that is in the \
following folder on disk 1 of your Mac OS X installation DVD:\n/Welcome to Mac \
OS X/Optional Installs.\n\nNow quit."
button=`/usr/bin/osascript << EOT
    tell application "Finder"
    beep
    display dialog "$message1" buttons {"Quit"} \
        with icon caution default button "Quit"
    set result to button returned of result
    end tell
EOT`
if test "$button" == "Quit"; then                # Quit application
    exit 112
fi
}

function bsd_command_check {      # written by Patrick Luby    
commands="awk cp defaults diskutil echo grep ln mkfifo mkdir mv \
plutil ps rm sed sleep sw_vers touch rsync"
for i in $commands ; do
    if [ ! -x "/usr/bin/$i" -a ! -x "/bin/$i" -a ! -x "/usr/sbin/$i" -a \
    ! -x "/sbin/$i" ] ; then
        # Return 96 + 16 if a command is not found
        command_check_msg;
        exit 112;
    fi
done
}

# ========================================================
# get_p_app
# Open dialog to get Portable app bundle to patch
# ===========================================================

function get_p_app {
    rvf=` "$CD" fileselect --title "Select Portable Application" --text "Please select \
Portable Application to patch:" --with-directory /Volumes --with-extensions .app `
    if [ -n "$rvf" ]; then  ### if $rv has a non-zero length
        p_path="$rvf";
        s_app=` defaults read "$p_path/Contents/Info" CFBundleName `
        case "${s_app}" in
            'Portable Safari') ;;
            'Portable Mail') ;;
        #    'Portable Address Book') ;;    # not Lion compatible
        #    'Portable iChat') ;;        # not Lion compatible
        #    'Portable iCal') ;;            # not Lion compatible
            'SyncPAppX') ;;
            'Portable Abiword') ;;
            'Portable Adium') ;;
            'Portable Audacity') ;;
            'Portable Camino') ;;
            'Portable Celtx') ;;
            'Portable CheckOff') ;;
            'Portable Chromium') ;;
            'Portable Cyberduck') ;;
            'Portable Feed') ;;
            'Portable Firefox') ;;
            'FirefoxLive') ;;    
            'Portable Gimp') ;;
            'Portable Inkscape') ;;
            'Portable LibreOffice') ;;
            'Portable Newspeak') ;;
            'Portable Nvu') ;;
            'Portable OpenOffice.org') ;;
            'Portable RSSOwl') ;;
            'Portable Sunbird') ;;
            'Portable Thunderbird') ;;
            'Portable Vienna') ;;
            'Portable VLC') ;;
            'Portable X-Chat Aqua') ;;
            * ) wrong_path;;
        esac
    else
        exit 0
    fi    
}

function wrong_path {
    rv=` CDokmessagec "Portable Application not selected" \
"You have not selected a compatible Portable Application to patch. \
Try again?"`
        if [ "$rv" == "1" ] ; then
            get_p_app
        elif [ "$rv" == "2" ] ; then
            exit 0
        fi
}

# ========================================================
# quitapp - disabled
# Check if local or portable app is open and quit
# ========================================================

function quitapp {
    if ps cx | grep "$1"'$' > /dev/null; then
        rv=` CDokmessage "$1 is already running on this system" \
        "Quit runnig $1 and reopen PAppsLionPatch." "--no-cancel" `
        if [ "$rv" == "1" ] ; then                # Quit application
            exit 0
        fi
    fi
}

function copycocaodialog { ## all copy work done here
#    quitapp "${1}"
    CDold="$p_path/Contents/Resources/CocoaDialog.app"
    p_appicon="$p_path/Contents/Resources/appIcon.icns"
    # rm -R "$CDold"
    "$CD" bubble --title "Patch $1" \
    --text "Patch \"$1\" in progress. Please wait few seconds..." \
    --icon-file "$p_appicon" \
    --x-placement "center" --y-placement "center" \
    --background-top "dedede" --background-bottom "bfbfbf"
    cp -R "$p_userbase/CocoaDialog.app/" "$CDold"

}

function patch {
    if copycocaodialog "${1}" ; then
        rv=` "$CD" msgbox --no-newline \
            --title "Portable Apps Lion Patch" \
            --text "Patch $1 done" \
            --informative-text "Patch $1 end with success." \
            --icon-file "$p_appicon" \
                --button1 "Patch more…" --button2 "Quit" --button3 "Donate"`
        if [ "$rv" == "1" ]; then
            patch_p_app
        elif [ "$rv" == "2" ]; then
            exit 0
        elif [ "$rv" == "3" ]; then
        open "http://pledgie.com/campaigns/15006"
        exit 0
        fi
    else
        CDokmessagec "Patch $1 error" \
"An error occour while perform patch. Now quit." "--no-cancel" > /dev/null
        exit 0
    fi
}

function patch_p_app {
        get_p_app
        patch "${s_app}"
}

function info_window {
        rv=` "$CD" msgbox --no-newline \
            --title "Portable Apps Lion Patch" \
            --text "Patch info" \
            --informative-text "This Patch will solve Mac OS X 10.7 Lion incompatibility with some PowerPC code inside Portable Applications app bundle." \
            --icon-file "$appicon" \
                --button1 "Patch Portable Apps…" --button2 "Quit" --button3 "Donate"`
        if [ "$rv" == "1" ]; then
            patch_p_app  ## perform patch
        elif [ "$rv" == "2" ]; then
            exit 0
        elif [ "$rv" == "3" ]; then
            open "http://pledgie.com/campaigns/15006"
            exit 0
        fi
}

bsd_command_check
info_window

exit 0

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