#!/bin/bash # script: appify.sh # minor edits from https://gist.github.com/advorak/1403124 # usage and cli args usage="Creates the simplest possible Mac app from a shell script.\n\ Usage: `basename "$0"` -s -n \n\ [optional: -i -h ]\n\ \n\ Copyright (c) Thomas Aylott \n\ Modified by Mathias Bynens \n\ Modified by Andrew Dvorak \n\ Modified by Stephane Plaisance (support for opt:arguments)" while getopts "s:n:i:h" opt; do case $opt in s) script=${OPTARG} ;; n) name=${OPTARG} ;; i) icon=${OPTARG} ;; h) echo -e ${usage} >&2; exit 0 ;; \?) echo "Invalid option: -$OPTARG" >&2; exit 1 ;; *) echo "this command requires arguments, try -h" >&2; exit 1 ;; esac done # test minimal argument if [ -z "${script}" ]; then echo "# no input script provided!" echo -e ${usage} >&2 exit 1 fi # test input files if [ ! -f "${script}" ]; then echo "# ${script} file not found!" >&2 exit 1 fi # test optional args if [ -z "${name}" ]; then APPNAME=$(basename "${script}" ".sh") else APPNAME=${name} fi if [ -a "${APPNAME}.app" ]; then echo "# $PWD/${APPNAME}.app already exists, use -n !" >&2 exit 1 fi if [ -z "${icon}" ]; then # support for custom icon with default ICONFOLD="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/" CUSTICON="${ICONFOLD}/GenericApplicationIcon.icns" else CUSTICON=${icon} fi if [ ! -f ${CUSTICON} ]; then echo "# ${CUSTICON} file not found!" >&2 exit 1 fi # define output path DIR="${APPNAME}.app/Contents" mkdir -p $DIR/{MacOS,Resources} || (echo "error creating the App container" >&2; exit 1); # Copy Apple's GenericApplicationIcon to our application. cp "${CUSTICON}" "${DIR}/Resources/${APPNAME}.icns" cp "${script}" "${DIR}/MacOS/${APPNAME}" chmod +x "${DIR}/MacOS/${APPNAME}" cat < $DIR/Info.plist CFBundleExecutable $APPNAME CFBundleGetInfoString $APPNAME CFBundleIconFile $APPNAME CFBundleName $APPNAME CFBundlePackageType APPL EOF echo "$PWD/${APPNAME}.app was created"