Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
appify. Create the simplest possible mac app from a shell script
#!/usr/bin/env bash
#
# url : https://gist.github.com/672684
# version : 2.0.2
# name : appify
# description : Create the simplest possible mac app from a shell script.
# usage : cat my-script.sh | appify MyApp
# platform : Mac OS X
# author : Thomas Aylott <oblivious@subtlegradient.com>
APPNAME=${1:-Untitled}
if [[ -a "$APPNAME.app" ]]; then
echo "App already exists :'(" >&2
echo "$PWD/$APPNAME.app"
exit 1
fi
mkdir -p "$APPNAME.app/Contents/MacOS"
touch "$APPNAME.app/Contents/MacOS/$APPNAME"
chmod +x "$APPNAME.app/Contents/MacOS/$APPNAME"
DONE=false
until $DONE ;do
read || DONE=true
echo "$REPLY" >> "$APPNAME.app/Contents/MacOS/$APPNAME"
done
echo "$PWD/$APPNAME.app"
@mathiasbynens

This comment has been minimized.

Copy link

commented Nov 11, 2010

Posting this here too:

“The application My.app cannot be opened because it has an incorrect executable format”?
Try adding a #! shebang to My.app/Contents/MacOS/My

@subtleGradient

This comment has been minimized.

Copy link
Owner Author

commented Nov 11, 2010

New hello world example for appify 2.0

appify Howdy
#!/usr/bin/osascript
say "Howdy"

⌃D

open -a Howdy
@subtleGradient

This comment has been minimized.

Copy link
Owner Author

commented Nov 11, 2010

"You can't open the application Test because it is not supported on this type of Mac."
Same deal. Try adding a #! shebang line.

@paulirish

This comment has been minimized.

Copy link

commented Nov 12, 2010

Mathias, did you augment this for chrome execution with flags? would love to get that. :>

@mathiasbynens

This comment has been minimized.

Copy link

commented Nov 12, 2010

appify v2.0.1 assumes my-script.sh has a newline at the end of the file. If not, it will chop off the last line, effectively breaking the generated app. I’ve fixed this in my fork of this gist, by replacing the while read loop with this:

DONE=false
until $DONE ;do
  read || DONE=true
  echo "$REPLY" >> "$APPNAME.app/Contents/MacOS/$APPNAME"
done

Paul: http://mathiasbynens.be/notes/shell-script-mac-apps#chrome-bootstrappers

@subtleGradient

This comment has been minimized.

Copy link
Owner Author

commented Nov 12, 2010

Updated to your 2.0.2!
Thanks Mathias!

@subtleGradient

This comment has been minimized.

@mathiasbynens

This comment has been minimized.

Copy link

commented Nov 12, 2010

You could also add [[ ! $REPLY ]] && continue after line 25, which will cause all redundant newlines to be skipped. (See my fork.)

@subtleGradient

This comment has been minimized.

Copy link
Owner Author

commented Nov 12, 2010

Maybe it should just cp the file in there instead and avoid all these silly issues.

@mathiasbynens

This comment has been minimized.

Copy link

commented Jul 19, 2011

Hey @subtleGradient, I just rewrote appify so it uses cp which avoids a lot of problems. Check it out: https://gist.github.com/674099

@andreif

This comment has been minimized.

Copy link

commented Jun 6, 2015

It wouldn't work on OS X 10.10 until I added $APPNAME.app/Contents/Info.plist containing at least <plist><dict></dict></plist>

@phasstw

This comment has been minimized.

Copy link

commented Aug 9, 2016

I created an app, but it won't execute when I double-click on the bundle. It is just a #!/bin/sh script that has a echo "hello world" statement in it for testing purposes. Can someone give me some guidance on how to get my app to run from clicking on the bundle? Appify did not create a Info.plist file for me, maybe this is the issue? What needs to be in that file? Thanks!

@oubiwann

This comment has been minimized.

Copy link

commented Dec 9, 2016

I forked this and added option-parsing, overridable icons file, and some other bits: https://gist.github.com/oubiwann/453744744da1141ccc542ff75b47e0cf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.