Creating an application stack for a script

I’m sure there are others like myself who just want to run a script from the Applications folder. Nothing special, just a Unix script that runs a ‘wine’ command, or just about anything really. Unfortunately it’s not terribly pretty to simply rename it to xyz.command. I ran across a script that creates a stub body of OSX application stack for the script. It’s called applify. Basically all you have to do is:

applify scriptname “name you want to give it”

It will create a directory called name you want to give it.app and you can drag-n-drop it wherever and run it from there with a click. I use it for wine applications right now, and probably unix scripts in the future.

I found the script at: https://gist.github.com/mathiasbynens/674099

I pasted the following into a script in /usr/local/bin which is in my path, and it’s ready to go:

#!/bin/bash

if [ “$1” = “-h” -o “$1” = “–help” -o -z “$1” ]; then cat <<EOF
appify v3.0.1 for Mac OS X – http://mths.be/appify
Creates the simplest possible Mac app from a shell script.

Appify takes a shell script as its first argument:

`basename “$0″` my-script.sh

Note that you cannot rename appified apps. If you want to give your app
a custom name, use the second argument:

`basename “$0″` my-script.sh “My App”

Copyright (c) Thomas Aylott
Modified by Mathias Bynens
EOF
exit; fi

APPNAME=${2:-$(basename “$1” “.sh”)}
DIR=”$APPNAME.app/Contents/MacOS”

if [ -a “$APPNAME.app” ]; then
echo “$PWD/$APPNAME.app already exists :(”
exit 1
fi

mkdir -p “$DIR”
cp “$1” “$DIR/$APPNAME”
chmod +x “$DIR/$APPNAME”

echo “$PWD/$APPNAME.app”

 

EDIT 01/18/2015:

To give an example of the script I’m using with Wine to run an application, my Microsoft Money script is as follows:

#!/bin/bash
/Applications/Wine.app/Contents/Resources/bin/wine ‘/Users/situationalawareness/.wine/drive_c/Program Files/Microsoft Money/System/msmoney.exe’

I ran:
applify money.sh “MS money”

and it created an “application” in that folder that can be drag-and-dropped anywhere in Finder.  (i.e. into Applications)

Another note is how to edit the icon for the “Application” created.  First, create/find an icon around 512×512 in resolution.  Then, open it in your favorite editor, select all and copy to the buffer. (command-c)  Then, right click on the “Application”, and select “get info”.  Single-click on the icon picture in the upper left-hand corner of what popped up, then paste your buffer into there. (command-v)  The icon should appear in place.  It won’t be visible in the Applications folder until you’ve logged out and logged back in, however.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.