forked from xbapps/xbvr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appify.sh
executable file
·123 lines (96 loc) · 2.91 KB
/
appify.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env bash
VERSION=4.0.1
SCRIPT=`basename "$0"`
APPNAME="My App"
APPICONS="/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/GenericApplicationIcon.icns"
OSX_VERSION=`sw_vers -productVersion`
PWD=`pwd`
function usage {
cat <<EOF
$SCRIPT v${VERSION} for for Mac OS X - https://gist.github.com/oubiwann/453744744da1141ccc542ff75b47e0cf
Usage:
$SCRIPT [options]
Options:
-h, --help Prints this help message, then exits
-s, --script Name of the script to 'appify' (required)
-n, --name Name of the application (default "$APPNAME")
-i, --icons Name of the icons file to use when creating the app
(defaults to $APPICONS)
-v, --version Prints the version of this script, then exits
Description:
Creates the simplest possible Mac app from a shell script.
Appify has one required parameter, the script to appify:
$SCRIPT --script my-app-script.sh
Note that you cannot rename appified apps. If you want to give your app
a custom name, use the '--name' option
$SCRIPT --script my-app-script.sh --name "Sweet"
Copyright:
Copyright (c) Thomas Aylott <http://subtlegradient.com/>
Modified by Mathias Bynens <http://mathiasbynens.be/>
Modified by Andrew Dvorak <http://OhReally.net/>
Rewritten by Duncan McGreggor <http://github.com/oubiwann/>
EOF
exit 1
}
function version {
echo "v${VERSION}"
exit 1
}
function error {
echo
echo "ERROR: $1"
echo
usage
}
while :; do
case $1 in
-h | --help ) usage;;
-s | --script ) APPSCRIPT="$2"; shift ;;
-n | --name ) APPNAME="$2"; shift ;;
-i | --icons ) APPICONS="$2"; shift ;;
-v | --version ) version;;
-- ) shift; break ;;
* ) break ;;
esac
shift
done
if [ -z ${APPSCRIPT+nil} ]; then
error "the script to appify must be provided!"
fi
if [ ! -f "$APPSCRIPT" ]; then
error "the can't find the script '$APPSCRIPT'"
fi
if [ -a "$APPNAME.app" ]; then
error "the bundle '$PWD/$APPNAME.app' already exists"
fi
APPDIR="$APPNAME.app/Contents"
mkdir -vp "$APPDIR"/{MacOS,Resources}
cp -v "$APPICONS" "$APPDIR/Resources/$APPNAME.icns"
cp -v "$APPSCRIPT" "$APPDIR/MacOS/$APPNAME"
chmod +x "$APPDIR/MacOS/$APPNAME"
cat <<EOF > "$APPDIR/Info.plist"
<?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>$APPNAME</string>
<key>CFBundleGetInfoString</key>
<string>$APPNAME</string>
<key>CFBundleIconFile</key>
<string>$APPNAME</string>
<key>CFBundleName</key>
<string>$APPNAME</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>4242</string>
<key>LSUIElement</key>
<true/>
</dict>
</plist>
EOF
echo "Application bundle created at '$PWD/$APPNAME.app'"
echo
#mv $PWD/$APPNAME.app dist/darwin_amd64
#rm $APPSCRIPT