3 # appify -- convert non-interactive shell script into Mac OS X applications
4 # Copyright (C) 2010 Adam Backstrom
5 # Copyright (C) 2015 Alexander Barton <alex@barton.de>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with this program; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 echo "Usage: $0 [-h] <script.sh> <target.app> [<icons.icns>]"
41 if [ $# -lt 2 -o $# -gt 3 ]; then
49 BASENAME=`basename "$SCRIPT"`
51 if [ ! -r "$SCRIPT" ]; then
52 echo "$SCRIPT isn't readable!" 1>&2
56 if [ -e "$TARGET" ]; then
57 echo "$TARGET exists!" 1>&2
61 if [ -n "$ICON" -a ! -r "$ICON" ]; then
62 echo "$ICON isn't readable!" 1>&2
66 SCRIPTSIZE=$(ls -l "$SCRIPT" | awk '{print $5}')
68 if [ $SCRIPTSIZE -lt 28 ]; then
69 echo -e "Script smaller than size allowed by OS. Please pad to 28 characters." 1>&2
74 # done checking args; create the app
79 mkdir -p "$TARGET/Contents/MacOS" || exit 1
80 mkdir -p "$TARGET/Contents/Resources" || exit 1
82 cat <<EOF >"$TARGET/Contents/Info.plist"
83 <?xml version="1.0" encoding="UTF-8"?>
84 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
87 <key>CFBundleExecutable</key>
88 <string>${BASENAME}</string>
89 <key>CFBundleIconFile</key>
91 <key>CFBundleInfoDictionaryVersion</key>
93 <key>CFBundlePackageType</key>
95 <key>CFBundleSignature</key>
97 <key>CFBundleVersion</key>
101 if [ -n "$ICON" ]; then
102 cat <<EOF >>"$TARGET/Contents/Info.plist"
103 <key>CFBundleIconFile</key>
104 <string>app.icns</string>
106 cp "$ICON" "$TARGET/Contents/Resources/app.icns" || exit 1
109 cat <<EOF >>"$TARGET/Contents/Info.plist"
114 cp "$SCRIPT" "$TARGET/Contents/MacOS/$BASENAME" || exit 1
115 chmod 755 "$TARGET/Contents/MacOS/$BASENAME" || exit 1