Last active
August 29, 2015 14:14
-
-
Save hightemp/a15200310174cadc4c55 to your computer and use it in GitHub Desktop.
Allows you to easily create Mac apps from shell scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
INSTALLPATH="/usr/local/bin" | |
if [ "$1" = "install" ]; then | |
chmod +x $0 | |
cp $0 $INSTALLPATH/$(basename "$0" ".sh") | |
echo "Installed into $INSTALLPATH" | |
exit 0 | |
elif [ "$1" = "createapp" -o "$1" = "installapp" ]; then | |
EXT="${2##*.}" | |
APPNAME=${3:-$(basename "$2" ".$EXT")} | |
APPNAMEAPP="$APPNAME.app" | |
CONTENTS_DIR="$APPNAMEAPP/Contents" | |
MACOS_DIR="$CONTENTS_DIR/MacOS" | |
if [ "$1" = "createapp" ]; then | |
if [ -a "$APPNAMEAPP" ]; then | |
echo "$PWD/$APPNAMEAPP already exists :(" | |
exit 1 | |
fi | |
mkdir -p "$MACOS_DIR" | |
cat > "$CONTENTS_DIR/Info.plist" <<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>CFBundleName</key> <string>$APPNAME</string> | |
<key>CFBundleExecutable</key> <string>$APPNAME</string> | |
</dict> | |
</plist> | |
EOF | |
if [ ! "$EXT" = "sh" ]; then | |
FILENAME="$MACOS_DIR/$APPNAME.file" | |
if [[ "$2" = /* ]]; then | |
ln -s "$2" "$FILENAME" | |
else | |
if [ ! -f "$2" ]; then | |
ln -s $(which $2) "$FILENAME" | |
else | |
cp "$2" "$FILENAME" | |
chmod +x "$FILENAME" | |
fi | |
fi | |
cat > "$MACOS_DIR/$APPNAME" <<EOF | |
#!/usr/bin/env bash | |
cd $(dirname $0) | |
./$APPNAME.file $4 & | |
EOF | |
else | |
cp "$2" "$MACOS_DIR/$APPNAME" | |
fi | |
chmod +x "$MACOS_DIR/$APPNAME" | |
echo "created application file $APPNAMEAPP" | |
exit 0 | |
elif [ "$1" = "installapp" ]; then | |
mv "$APPNAMEAPP" "/Applications/$APPNAMEAPP" | |
echo "installed into /Applications/$APPNAMEAPP" | |
exit 0 | |
fi | |
elif [ "$1" = "h" -o "$1" = "help" -o -z "$1" ]; then | |
echo "$0 COMMAND ARG1 .." | |
echo " install - copy self to $INSTALLPATH" | |
echo " createapp SCRIPT NAME - create new application file" | |
echo " installapp SCRIPT NAME - install application to /Applications" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment