forked from lhl/chrome-ssb-osx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchrome-ssb.sh
executable file
·106 lines (88 loc) · 3.17 KB
/
chrome-ssb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
# White Space Trimming: http://codesnippets.joyent.com/posts/show/1816
trim() {
local var=$1
var="${var#"${var%%[![:space:]]*}"}" # remove leading whitespace characters
var="${var%"${var##*[![:space:]]}"}" # remove trailing whitespace characters
/bin/echo -n "$var"
}
### Get Input
/bin/echo "What should the Application be called?"
read inputline
name=`trim "$inputline"`
/bin/echo "What is the url (e.g. https://www.google.com/calendar/render)?"
read inputline
url=`trim "$inputline"`
/bin/echo "What is the full path to the icon (e.g. /Users/username/Desktop/icon.png)?"
read inputline
icon=`trim "$inputline"`
#### Find Chrome. If its not in the standard spot, try using spotlight.
chromePath="/Applications/Google Chrome.app"
if [ ! -d "$chromePath" ] ; then
chromePath=`mdfind "kMDItemCFBundleIdentifier == 'com.google.Chrome'" | head -n 1`
if [ -z "$chromePath" ] ; then
/bin/echo "ERROR. Where is chrome installed?!?!"
exit 1
fi
fi
chromeExecPath="$chromePath/Contents/MacOS/Google Chrome"
# Let's make the app whereever we call the script from...
appRoot=`/bin/pwd`
# 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"
versionsPath="$appRoot/$name.app/Contents/Versions"
# make the directories
/bin/mkdir -p "$resourcePath" "$execPath" "$profilePath"
# convert the icon and copy into Resources
if [ -f "$icon" ] ; then
if [ ${icon: -5} == ".icns" ] ; then
/bin/cp "$icon" "$resourcePath/icon.icns"
else
sips -s format tiff "$icon" --out "$resourcePath/icon.tiff" --resampleWidth 128 >& /dev/null
tiff2icns -noLarge "$resourcePath/icon.tiff" >& /dev/null
fi
fi
# Save a symlink to the location of the Chrome executable to be copied when the SSB is started.
/bin/ln -s "$chromeExecPath" "$execPath/Chrome"
### Create the wrapper executable
/bin/cat >"$execPath/$name" <<EOF
#!/bin/sh
ABSPATH=\$(cd "\$(dirname "\$0")"; pwd)
/bin/cp "\$ABSPATH/Chrome" "\$ABSPATH/$name Chrome"
exec "\$ABSPATH/$name Chrome" --app="$url" --user-data-dir="\$ABSPATH/../Profile" "\$@"
EOF
/bin/chmod +x "$execPath/$name"
### create the Info.plist
/bin/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>CFBundleName</key>
<string>$name</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>NSHighResolutionCapable</key>
<string>True</string>
</dict>
</plist>
EOF
### link the Versions directory
/bin/ln -s "$chromePath/Contents/Versions" "$versionsPath"
### create a default (en) localization to name the app
/bin/mkdir -p "$resourcePath/en.lproj"
/bin/cat > "$resourcePath/en.lproj/InfoPlist.strings" <<EOF
CFBundleDisplayName = "$name";
CFBundleName = "$name";
EOF
### tell the user where the app is located so that they can move it to
### /Applications if they wish
/bin/cat <<EOF
Finished! The app has been installed in
$appRoot/$name.app
EOF