Skip to content

Instantly share code, notes, and snippets.

@jcanfield
Created August 16, 2012 19:32
Show Gist options
  • Save jcanfield/3372934 to your computer and use it in GitHub Desktop.
Save jcanfield/3372934 to your computer and use it in GitHub Desktop.
Create WebApp with Chrome on Mac OSX
#!/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 --resampleWidth 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
codeclarity:.bin jcanfield$ chmod +x makeapp.sh
codeclarity:.bin jcanfield$ ./makeapp.sh
What should the Application be called (no spaces allowed e.g. GCal)?
BrowserStack
What is the url (e.g. https://www.google.com/calendar/render)?
http://www.browserstack.com/user/dashboard
What is the full path to the icon (e.g. /Users/username/Desktop/icon.png)?
//Users/jcanfield/Documents/resources/Web Resources/icons/browser-stack.png
./makeapp.sh: line 33: [: //Users/jcanfield/Documents/resources/Web: binary operator expected
codeclarity:.bin jcanfield$ ./makeapp.sh
What should the Application be called (no spaces allowed e.g. GCal)?
BrowserStack
What is the url (e.g. https://www.google.com/calendar/render)?
http://www.browserstack.com/user/dashboard
What is the full path to the icon (e.g. /Users/username/Desktop/icon.png)?
/Users/jcanfield/Documents/resources/Web \Resources/icons/browser-stack.png
./makeapp.sh: line 33: [: /Users/jcanfield/Documents/resources/Web: binary operator expected
codeclarity:.bin jcanfield$ ./makeapp.sh
What should the Application be called (no spaces allowed e.g. GCal)?
BrowserStack
What is the url (e.g. https://www.google.com/calendar/render)?
http://www.browserstack.com/user/dashboard
What is the full path to the icon (e.g. /Users/username/Desktop/icon.png)?
/Users/jcanfield/tmp/browser-stack.png
codeclarity:.bin jcanfield$ cd ..
codeclarity:~ jcanfield$ cd tmp
codeclarity:tmp jcanfield$ ls
DumpLog 12-06-22 20:47 DumpLog 12-06-22 22:25 DumpLog 12-06-22 22:51 Pictures_03112011.rar Pictures_25122010 hardlink
DumpLog 12-06-22 20:59 DumpLog 12-06-22 22:50 DumpLog 12-06-22 22:58 Pictures_05052012.zip browser-stack.png send-txt.sh
codeclarity:tmp jcanfield$ pwd
/Users/jcanfield/tmp
codeclarity:tmp jcanfield$ sh ../.bin/makeapp.sh
What should the Application be called (no spaces allowed e.g. GCal)?
BrowserStack
What is the url (e.g. https://www.google.com/calendar/render)?
http://www.browserstack.com/user/dashboard
What is the full path to the icon (e.g. /Users/username/Desktop/icon.png)?
/Users/jcanfield/tmp/browser-stack.png
codeclarity:tmp jcanfield$ cat ../.bin/makeapp.sh
#!/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 --resampleWidth 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment