Skip to content

Instantly share code, notes, and snippets.

@lalyos
Forked from oubiwann/appify.sh
Created March 24, 2022 05:48
Show Gist options
  • Select an option

  • Save lalyos/43f0e31bdb66cbdde1ba8664d951f3f5 to your computer and use it in GitHub Desktop.

Select an option

Save lalyos/43f0e31bdb66cbdde1ba8664d951f3f5 to your computer and use it in GitHub Desktop.

Revisions

  1. @oubiwann oubiwann revised this gist Dec 9, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion appify.sh
    Original file line number Diff line number Diff line change
    @@ -95,7 +95,7 @@ chmod +x "$APPDIR/MacOS/$APPNAME"

    cat <<EOF > "$APPDIR/Info.plist"
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>CFBundleExecutable</key>
  2. @oubiwann oubiwann revised this gist Dec 9, 2016. 1 changed file with 25 additions and 29 deletions.
    54 changes: 25 additions & 29 deletions appify.sh
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #!/usr/bin/env bash

    VERSION=4.0.0
    VERSION=4.0.1
    SCRIPT=`basename "$0"`
    APPNAME="My App"
    APPICONS="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericApplicationIcon.icns"
    @@ -61,23 +61,17 @@ function error {
    usage
    }

    OPTIND=1
    OPTS=`getopt -o hsniv: --long help,script,name,icons: -n 'parse-options' -- "$@"`
    if [ $? != 0 ]; then
    error "Failed parsing options" >&2
    usage
    fi

    while true; do
    case "$1" in
    -h | --help ) usage; shift ;;
    -s | --script ) APPSCRIPT="$2"; shift ;;
    -n | --name ) APPNAME="$2"; shift ;;
    -i | --icons ) APPICONS="$2"; shift ;;
    -v | --version ) version; shift; shift ;;
    -- ) shift; break ;;
    * ) break ;;
    while :; do
    case $1 in
    -h | --help ) usage;;
    -s | --script ) APPSCRIPT="$2"; shift ;;
    -n | --name ) APPNAME="$2"; shift ;;
    -i | --icons ) APPICONS="$2"; shift ;;
    -v | --version ) version;;
    -- ) shift; break ;;
    * ) break ;;
    esac
    shift
    done

    if [ -z ${APPSCRIPT+nil} ]; then
    @@ -103,18 +97,20 @@ cat <<EOF > "$APPDIR/Info.plist"
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>CFBundleExecutable</key>
    <string>$APPNAME</string>
    <key>CFBundleGetInfoString</key>
    <string>$APPNAME</string>
    <key>CFBundleIconFile</key>
    <string>$APPNAME</string>
    <key>CFBundleName</key>
    <string>$APPNAME</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    </dict>
    <dict>
    <key>CFBundleExecutable</key>
    <string>$APPNAME</string>
    <key>CFBundleGetInfoString</key>
    <string>$APPNAME</string>
    <key>CFBundleIconFile</key>
    <string>$APPNAME</string>
    <key>CFBundleName</key>
    <string>$APPNAME</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleSignature</key>
    <string>4242</string>
    </dict>
    </plist>
    EOF

  3. @oubiwann oubiwann revised this gist Dec 8, 2016. 1 changed file with 90 additions and 30 deletions.
    120 changes: 90 additions & 30 deletions appify.sh
    100644 → 100755
    Original file line number Diff line number Diff line change
    @@ -1,47 +1,105 @@
    #!/bin/bash
    #!/usr/bin/env bash

    if [ "$1" = "-h" -o "$1" = "--help" ]; then cat <<EOF
    appify v3.0.0 for Mac OS X - http://mths.be/appify
    Creates the simplest possible Mac app from a shell script.
    VERSION=4.0.0
    SCRIPT=`basename "$0"`
    APPNAME="My App"
    APPICONS="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericApplicationIcon.icns"
    OSX_VERSION=`sw_vers -productVersion`
    PWD=`pwd`

    Appify takes a shell script as its first argument:
    function usage {
    cat <<EOF
    `basename "$0"` my-script.sh
    $SCRIPT v${VERSION} for for Mac OS X - https://gist.github.com/oubiwann/453744744da1141ccc542ff75b47e0cf
    Note that you cannot rename appified apps. If you want to give your app
    a custom name, use the second argument:
    Usage:
    `basename "$0"` my-script.sh "My App"
    $SCRIPT [options]
    Copyright (c) Thomas Aylott <http://subtlegradient.com/>
    Modified by Mathias Bynens <http://mathiasbynens.be/>
    Modified by Andrew Dvorak <http://OhReally.net/>
    EOF
    exit; fi
    Options:
    # OSX_VERSION is currently unused, though knowing this may help, since the
    # GenericApplicationIcon.icns file may be located elsewhere pre-10.6.x
    OSX_VERSION=`sw_vers -productVersion`
    -h, --help Prints this help message, then exits
    -s, --script Name of the script to 'appify' (required)
    -n, --name Name of the application (default "$APPNAME")
    -i, --icons Name of the icons file to use when creating the app
    (defaults to $APPICONS)
    -v, --version Prints the version of this script, then exits
    APPNAME=${2:-$(basename "$1" ".sh")}
    DIR="$APPNAME.app/Contents"
    Description:
    if [ -a "$APPNAME.app" ]; then
    echo "$PWD/$APPNAME.app already exists :("
    Creates the simplest possible Mac app from a shell script.
    Appify has one required parameter, the script to appify:
    $SCRIPT --script my-app-script.sh
    Note that you cannot rename appified apps. If you want to give your app
    a custom name, use the '--name' option
    $SCRIPT --script my-app-script.sh --name "Sweet"
    Copyright:
    Copyright (c) Thomas Aylott <http://subtlegradient.com/>
    Modified by Mathias Bynens <http://mathiasbynens.be/>
    Modified by Andrew Dvorak <http://OhReally.net/>
    Rewritten by Duncan McGreggor <http://github.com/oubiwann/>
    EOF
    exit 1
    }

    function version {
    echo "v${VERSION}"
    exit 1
    }

    function error {
    echo
    echo "ERROR: $1"
    echo
    usage
    }

    OPTIND=1
    OPTS=`getopt -o hsniv: --long help,script,name,icons: -n 'parse-options' -- "$@"`
    if [ $? != 0 ]; then
    error "Failed parsing options" >&2
    usage
    fi

    while true; do
    case "$1" in
    -h | --help ) usage; shift ;;
    -s | --script ) APPSCRIPT="$2"; shift ;;
    -n | --name ) APPNAME="$2"; shift ;;
    -i | --icons ) APPICONS="$2"; shift ;;
    -v | --version ) version; shift; shift ;;
    -- ) shift; break ;;
    * ) break ;;
    esac
    done

    if [ -z ${APPSCRIPT+nil} ]; then
    error "the script to appify must be provided!"
    fi

    if [ ! -f "$APPSCRIPT" ]; then
    error "the can't find the script '$APPSCRIPT'"
    fi

    mkdir -p $DIR/{MacOS,Resources}
    if [ -a "$APPNAME.app" ]; then
    error "the bundle '$PWD/$APPNAME.app' already exists"
    fi

    # Copy Apple's GenericApplicationIcon to our application.
    # - TODO: provide command-line options for specifying an icon to use
    # (maybe even allow the user to specify an)
    cp "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericApplicationIcon.icns" "$DIR/Resources/$APPNAME.icns"
    APPDIR="$APPNAME.app/Contents"

    cp "$1" "$DIR/MacOS/$APPNAME"
    chmod +x "$DIR/MacOS/$APPNAME"
    mkdir -vp "$APPDIR"/{MacOS,Resources}
    cp -v "$APPICONS" "$APPDIR/Resources/$APPNAME.icns"
    cp -v "$APPSCRIPT" "$APPDIR/MacOS/$APPNAME"
    chmod +x "$APPDIR/MacOS/$APPNAME"

    cat <<EOF > $DIR/Info.plist
    cat <<EOF > "$APPDIR/Info.plist"
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    @@ -60,4 +118,6 @@ cat <<EOF > $DIR/Info.plist
    </plist>
    EOF

    echo "$PWD/$APPNAME.app"
    echo "Application bundle created at '$PWD/$APPNAME.app'"
    echo

  4. @advorak advorak renamed this gist Nov 29, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @advorak advorak revised this gist Nov 29, 2011. 1 changed file with 35 additions and 5 deletions.
    40 changes: 35 additions & 5 deletions appify
    Original file line number Diff line number Diff line change
    @@ -15,19 +15,49 @@ a custom name, use the second argument:
    Copyright (c) Thomas Aylott <http://subtlegradient.com/>
    Modified by Mathias Bynens <http://mathiasbynens.be/>
    Modified by Andrew Dvorak <http://OhReally.net/>
    EOF
    exit; fi

    # OSX_VERSION is currently unused, though knowing this may help, since the
    # GenericApplicationIcon.icns file may be located elsewhere pre-10.6.x
    OSX_VERSION=`sw_vers -productVersion`

    APPNAME=${2:-$(basename "$1" ".sh")}
    DIR="$APPNAME.app/Contents/MacOS"
    DIR="$APPNAME.app/Contents"

    if [ -a "$APPNAME.app" ]; then
    echo "$PWD/$APPNAME.app already exists :("
    exit 1
    fi

    mkdir -p "$DIR"
    cp "$1" "$DIR/$APPNAME"
    chmod +x "$DIR/$APPNAME"
    mkdir -p $DIR/{MacOS,Resources}

    # Copy Apple's GenericApplicationIcon to our application.
    # - TODO: provide command-line options for specifying an icon to use
    # (maybe even allow the user to specify an)
    cp "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericApplicationIcon.icns" "$DIR/Resources/$APPNAME.icns"

    cp "$1" "$DIR/MacOS/$APPNAME"
    chmod +x "$DIR/MacOS/$APPNAME"

    cat <<EOF > $DIR/Info.plist
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>CFBundleExecutable</key>
    <string>$APPNAME</string>
    <key>CFBundleGetInfoString</key>
    <string>$APPNAME</string>
    <key>CFBundleIconFile</key>
    <string>$APPNAME</string>
    <key>CFBundleName</key>
    <string>$APPNAME</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    </dict>
    </plist>
    EOF

    echo "$PWD/$APPNAME.app"
    echo "$PWD/$APPNAME.app"
  6. @mathiasbynens mathiasbynens revised this gist Sep 17, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion appify
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ exit; fi
    APPNAME=${2:-$(basename "$1" ".sh")}
    DIR="$APPNAME.app/Contents/MacOS"

    if [[ -a "$APPNAME.app" ]]; then
    if [ -a "$APPNAME.app" ]; then
    echo "$PWD/$APPNAME.app already exists :("
    exit 1
    fi
  7. @mathiasbynens mathiasbynens revised this gist Jul 19, 2011. 1 changed file with 27 additions and 24 deletions.
    51 changes: 27 additions & 24 deletions appify
    Original file line number Diff line number Diff line change
    @@ -1,30 +1,33 @@
    #!/usr/bin/env bash
    #
    # url : https://gist.github.com/672684
    # version : 2.0.3
    # name : appify
    # description : Create the simplest possible mac app from a shell script.
    # usage : cat my-script.sh | appify MyApp
    # platform : Mac OS X
    # author : Thomas Aylott <[email protected]>

    APPNAME=${1:-Untitled}
    #!/bin/bash

    if [ "$1" = "-h" -o "$1" = "--help" ]; then cat <<EOF
    appify v3.0.0 for Mac OS X - http://mths.be/appify
    Creates the simplest possible Mac app from a shell script.
    Appify takes a shell script as its first argument:
    `basename "$0"` my-script.sh
    Note that you cannot rename appified apps. If you want to give your app
    a custom name, use the second argument:
    `basename "$0"` my-script.sh "My App"
    Copyright (c) Thomas Aylott <http://subtlegradient.com/>
    Modified by Mathias Bynens <http://mathiasbynens.be/>
    EOF
    exit; fi

    APPNAME=${2:-$(basename "$1" ".sh")}
    DIR="$APPNAME.app/Contents/MacOS"

    if [[ -a "$APPNAME.app" ]]; then
    echo "App already exists :'(" >&2
    echo "$PWD/$APPNAME.app"
    exit 1
    echo "$PWD/$APPNAME.app already exists :("
    exit 1
    fi

    mkdir -p "$APPNAME.app/Contents/MacOS"
    touch "$APPNAME.app/Contents/MacOS/$APPNAME"
    chmod +x "$APPNAME.app/Contents/MacOS/$APPNAME"

    DONE=false
    until $DONE ;do
    read || DONE=true
    [[ ! $REPLY ]] && continue
    echo "$REPLY" >> "$APPNAME.app/Contents/MacOS/$APPNAME"
    done
    mkdir -p "$DIR"
    cp "$1" "$DIR/$APPNAME"
    chmod +x "$DIR/$APPNAME"

    echo "$PWD/$APPNAME.app"
  8. @mathiasbynens mathiasbynens revised this gist Nov 12, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion appify
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env bash
    #
    # url : https://gist.github.com/672684
    # version : 2.0.2
    # version : 2.0.3
    # name : appify
    # description : Create the simplest possible mac app from a shell script.
    # usage : cat my-script.sh | appify MyApp
  9. @mathiasbynens mathiasbynens revised this gist Nov 12, 2010. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions appify
    Original file line number Diff line number Diff line change
    @@ -23,6 +23,7 @@ chmod +x "$APPNAME.app/Contents/MacOS/$APPNAME"
    DONE=false
    until $DONE ;do
    read || DONE=true
    [[ ! $REPLY ]] && continue
    echo "$REPLY" >> "$APPNAME.app/Contents/MacOS/$APPNAME"
    done

  10. @mathiasbynens mathiasbynens revised this gist Nov 12, 2010. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions appify
    Original file line number Diff line number Diff line change
    @@ -26,6 +26,4 @@ until $DONE ;do
    echo "$REPLY" >> "$APPNAME.app/Contents/MacOS/$APPNAME"
    done

    echo "" >> "$APPNAME.app/Contents/MacOS/$APPNAME"

    echo "$PWD/$APPNAME.app"
  11. @mathiasbynens mathiasbynens revised this gist Nov 12, 2010. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions appify
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env bash
    #
    # url : https://gist.github.com/672684
    # version : 2.0.1
    # version : 2.0.2
    # name : appify
    # description : Create the simplest possible mac app from a shell script.
    # usage : cat my-script.sh | appify MyApp
    @@ -20,8 +20,12 @@ mkdir -p "$APPNAME.app/Contents/MacOS"
    touch "$APPNAME.app/Contents/MacOS/$APPNAME"
    chmod +x "$APPNAME.app/Contents/MacOS/$APPNAME"

    while read SCRIPT_SOURCE_LINE; do
    echo "$SCRIPT_SOURCE_LINE" >> "$APPNAME.app/Contents/MacOS/$APPNAME"
    DONE=false
    until $DONE ;do
    read || DONE=true
    echo "$REPLY" >> "$APPNAME.app/Contents/MacOS/$APPNAME"
    done

    echo "$PWD/$APPNAME.app"
    echo "" >> "$APPNAME.app/Contents/MacOS/$APPNAME"

    echo "$PWD/$APPNAME.app"
  12. @subtleGradient subtleGradient revised this gist Nov 11, 2010. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions appify
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/usr/bin/env bash
    #
    # url : https://gist.github.com/672684
    # version : 2.0
    # version : 2.0.1
    # name : appify
    # description : Create the simplest possible mac app from a shell script.
    # usage : cat my-script.sh | appify MyApp
    @@ -11,7 +11,7 @@
    APPNAME=${1:-Untitled}

    if [[ -a "$APPNAME.app" ]]; then
    echo "App already exists" >&2
    echo "App already exists :'(" >&2
    echo "$PWD/$APPNAME.app"
    exit 1
    fi
  13. @subtleGradient subtleGradient revised this gist Nov 11, 2010. 1 changed file with 20 additions and 7 deletions.
    27 changes: 20 additions & 7 deletions appify
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,27 @@
    #!/usr/bin/env bash
    # Create a new super simple mac app
    # Platform: Mac OS X
    # Author: Thomas Aylott <[email protected]>
    #
    # url : https://gist.github.com/672684
    # version : 2.0
    # name : appify
    # description : Create the simplest possible mac app from a shell script.
    # usage : cat my-script.sh | appify MyApp
    # platform : Mac OS X
    # author : Thomas Aylott <[email protected]>

    APPNAME=${1:-Untitled}

    if [[ -a "$APPNAME.app" ]]; then
    echo "App already exists" >&2
    echo "$PWD/$APPNAME.app"
    exit 1
    fi

    mkdir -p "$APPNAME.app/Contents/MacOS"
    cat > "$APPNAME.app/Contents/MacOS/$APPNAME" <<EOF
    #!/usr/bin/osascript
    say "Hello"
    EOF
    touch "$APPNAME.app/Contents/MacOS/$APPNAME"
    chmod +x "$APPNAME.app/Contents/MacOS/$APPNAME"

    while read SCRIPT_SOURCE_LINE; do
    echo "$SCRIPT_SOURCE_LINE" >> "$APPNAME.app/Contents/MacOS/$APPNAME"
    done

    echo "$PWD/$APPNAME.app"
  14. @subtleGradient subtleGradient created this gist Nov 11, 2010.
    14 changes: 14 additions & 0 deletions appify
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/usr/bin/env bash
    # Create a new super simple mac app
    # Platform: Mac OS X
    # Author: Thomas Aylott <[email protected]>

    APPNAME=${1:-Untitled}

    mkdir -p "$APPNAME.app/Contents/MacOS"
    cat > "$APPNAME.app/Contents/MacOS/$APPNAME" <<EOF
    #!/usr/bin/osascript
    say "Hello"
    EOF
    chmod +x "$APPNAME.app/Contents/MacOS/$APPNAME"
    echo "$PWD/$APPNAME.app"