December 28, 2007

Turn any shell script into a double-clickable app!

Filed under: ResearchAndDevelopment — Ryan Wilcox @ 1:37 am

So, while this might be very obvious to other people, I found out an interesting thing about bundles today. In short, if you configure your Info.plist correctly, and have the right permissions for everything, it doesn’t matter what you put as you executable.

For example, I have a shell script I want to send someone, but they aren’t computer savvy, so I want it to be a double-clickable app. How do I do this? There are a few tools that help you here: Pashua can give your script a GUI, and can also encase it as a stand-alone app. (‘Cept I don’t really need the GUI part, thank you). DropScript works, but only triggers the shell script when you drop a file onto the app (but I don’t want that either, in my situation).

Looking at Pashua’s stand-alone app, I had a thought, and here’s my method for making app an out of anything.

  1. Start with an empty app bundle.
    You can either build one yourself, or use the one that comes with Pashua’s Sample Stand-Alone app.
  2. Put your shell script into your bundle’s Contents/MacOS/ folder. Make it executable. (For the user and group) with chmod ug+x in Terminal.
  3. Modify Info.plist’s CFBundleName to be the name of your, well, app bundle. Also (and most importantly) modify CFBundleExecutable to be the name of your shell script from step #2.
  4. Double-click you app: your script should have run!

Sadly, if something goes wrong, the system won’t tell you anything. Not a thing. (It’ll just do a half-bounce of the app in the Dock. Or say that the app bundle is damaged.) So you just have to troubleshoot it on your own. Good Luck there.

This shell script of course assumes that all your script needs is right installed on the user’s system. Which might be right in controlled situations. But for (say) Python (or PyObjC) applications, you really should be building with py2app, which bundles up everything the script needs into the app, giving you a stand-alone solution that doesn’t even require that the user have Python (or have the right version of it).

1 Comment »

  1. Another option you might want to check out is Platypus – http://sveinbjorn.org/platypus

    Comment by Calrissian — December 20, 2011 @ 11:13 am

RSS feed for comments on this post. TrackBack URI

Leave a comment