Skip to content

Instantly share code, notes, and snippets.

@leyanlo
Forked from demonbane/makeapp.sh
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leyanlo/05cc1deea860d5043e75 to your computer and use it in GitHub Desktop.
Save leyanlo/05cc1deea860d5043e75 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Inspired by https://gist.github.com/demonbane/1065791
function pure_version() {
echo '0.1'
}
function version() {
echo "make-app $(pure_version)"
}
function usage() {
version
echo "Create a Fluid-style app launcher for single-window Chrome instances on OSX"
echo "Usage: $(basename $0) AppName http://url icon.png"
echo "Options:"
echo " --app-root"
echo " Path to where you would like the app installed"
echo " Defaults to '/Applications'"
echo " --chrome-path"
echo " Path to Chrome binary"
echo " Defaults to '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'"
echo " -h, --help display this help"
echo " --version show tool version number"
exit 0
}
APP_ROOT="/Applications"
CHROME_PATH="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
while test "${1:0:1}" = "-"; do
case $1 in
--app-root)
APP_ROOT="$2"
shift; shift;;
--chrome-path)
CHROME_PATH="$2"
shift; shift;;
-h | --help)
usage;;
--version)
version; exit 0;;
-*)
echo "Unknown option $1. Run with --help for help."
exit 1;;
esac
done
test -z "$3" && {
echo "Not enough arguments. Invoke with --help for help."
exit 1
}
NAME="$1" # e.g. GCal
URL="$2" # e.g. https://www.google.com/calendar/render
ICON="$3" # e.g. /Users/username/Desktop/icon.png
# various paths used when creating the app
RESOURCE_PATH="$APP_ROOT/$NAME.app/Contents/Resources"
EXEC_PATH="$APP_ROOT/$NAME.app/Contents/MacOS"
PROFILE_PATH="$APP_ROOT/$NAME.app/Contents/Profile"
PLIST_PATH="$APP_ROOT/$NAME.app/Contents/Info.plist"
# make the directories
mkdir -p ${RESOURCE_PATH} ${EXEC_PATH} ${PROFILE_PATH}
# convert the icon and copy into Resources
if [ -f ${ICON} ] ; then
sips -s format tiff ${ICON} --out ${RESOURCE_PATH}/icon.tiff --resampleWidth 128 >& /dev/null
tiff2icns -noLarge ${RESOURCE_PATH}/icon.tiff >& /dev/null
fi
# create the executable
cat >${EXEC_PATH}/${NAME} <<EOF
#!/bin/sh
exec ${CHROME_PATH} --app="${URL}" --user-data-dir="${PROFILE_PATH}" --no-default-browser-check --always-authorize-plugins "\$@"
EOF
chmod +x ${EXEC_PATH}/${NAME}
# create the Info.plist
cat > ${PLIST_PATH} <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!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>
<string>${NAME}</string>
<key>CFBundleIconFile</key>
<string>icon</string>
</dict>
</plist>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment