Skip to content

Instantly share code, notes, and snippets.

@sanfordredlich
Forked from demonbane/makeapp.sh
Last active March 28, 2022 14:19
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 11 You must be signed in to fork a gist
  • Save sanfordredlich/4568525 to your computer and use it in GitHub Desktop.
Save sanfordredlich/4568525 to your computer and use it in GitHub Desktop.
#!/bin/sh
echo "What should the Application be called (no spaces allowed e.g. GCal)?"
read inputline
name=$inputline
echo "What is the url (e.g. https://www.google.com/calendar/render)?"
read inputline
url=$inputline
echo "What is the full path to the icon (e.g. /Users/username/Desktop/icon.png)?"
read inputline
icon=$inputline
chromePath="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
appRoot="/Applications"
# various paths used when creating the app
resourcePath="$appRoot/$name.app/Contents/Resources"
execPath="$appRoot/$name.app/Contents/MacOS"
profilePath="$appRoot/$name.app/Contents/Profile"
plistPath="$appRoot/$name.app/Contents/Info.plist"
# make the directories
mkdir -p $resourcePath $execPath $profilePath
# convert the icon and copy into Resources
if [ -f $icon ] ; then
sips -s format tiff $icon --out $resourcePath/icon.tiff --resampleHeightWidth 128 128 >& /dev/null
tiff2icns -noLarge $resourcePath/icon.tiff >& /dev/null
fi
# create the executable
cat >$execPath/$name <<EOF
#!/bin/sh
exec $chromePath --app="$url" --user-data-dir="$profilePath" "\$@"
EOF
chmod +x $execPath/$name
# create the Info.plist
cat > $plistPath <<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
@myneur
Copy link

myneur commented Feb 2, 2016

It's great. The weak point is the app opens as a Google Chrome (although the dock name is by your choice).
That makes a problem when you launch your "app" before Chrome (or need to restart it). Launching Chrome will just focus your "app" instead of launching the Chrome. So you must close your "app", launch Chrome, and launch your "app" again.

@LutherianX
Copy link

This works really well. Thank you.
One question, how does one uninstall a created app. \ It doesn't seem to appear in the "Apps" menu.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment