Apple Intelligence now features Image Playground, Genmoji, Writing Tools enhancements, seamless support for ChatGPT, and visual intelligence.

Apple Intelligence has also begun language expansion with localized English support for Australia, Canada, Ireland, New Zealand, South Africa, and the U.K. Learn more >

You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to make a shell script double-clickable

I just installed a program that currently must be launched from a shell script, which, in turn, must be run from Terminal. Is there an easy way to create an alias with an icon that, when double-clicked, runs the script to launch the program? This would be trivial in Windows with a shortcut to a batch file, but I am having the darndest time figuring out how to do it in OS X. Google searches turned up a number of suggestions, all of which appear to be obsolete or accompanied by several follow-up posts to the effect that "I tried this and it didn't work." I tried a few of them, myself (such as changing .sh to .command), and they didn't work for me, either.

Any thoughts?

TIA,

Mark

MacBook Pro, Mac OS X (10.6.4)

Posted on Sep 30, 2010 10:21 PM

Reply
Question marked as Top-ranking reply

Posted on Sep 30, 2010 10:55 PM

If you give your script a .command extension and perform a chmod 777 on it (do make it executable), it will open and run in the Terminal when double-clicked.
6 replies

Oct 1, 2010 6:15 AM in response to red_menace

The following will work, but also opens the file up for write access to everybody. That write access may or may not be a desirable side-effect here.

chmod 777 file


With the "newer" chmod syntax, you can enable just execute (x) access for all (user, group, other) modes with this:

$ chmod ugo+x file


Or yes, sort out the individual bits in the mask and set those (rather than the 777 Big Hammer) with a numeric-syntax command.

Oct 1, 2010 6:18 AM in response to Mark92691

As red_menace points out, there is the .command suffix.

You can also download Platypus (free download)
<http://www.macupdate.com/info.php/id/12046/platypus>
which can turn any script or Unix command line program into a double-clickable app.

You can use Applications -> Automator -> Run Shell Script, and save the workflow as an application.

I kind-of-like Platypus as it lets you control how you display any output from your script. The .command approach will launch Applications -> Utilities -> Terminal, and leave the window sitting on your screen. If you do not need the Terminal session, you have the chore of closing Terminal after running your script.

Oct 5, 2010 11:25 PM in response to BobHarris

O.K., I can now run the script by double-clicking, but it fails. If run from Terminal, it succeeds. The purpose of the script is to launch a vendor (Oracle) program. Here's the script:

#!/bin/bash
cd "`dirname $0`"/bin && bash datamodeler.sh $*

It's run from the main vendor directory, in which sits a "bin" sub-directory, in which sits a shell script named "datamodeler.sh". I have (also) made it executable.

Here's the result of launching the outer script with a double-click:

==========

Last login: Tue Oct 5 23:19:02 on ttys001
/Applications/Oracle\ Data\ Modeler\ 2.0/datamodeler.sh.command ; exit;
Macintosh-6:~ mbwallace$ /Applications/Oracle\ Data\ Modeler\ 2.0/datamodeler.sh.command ; exit;
usage: dirname path
bash: datamodeler.sh: No such file or directory
logout

[Process completed]

==========

Again, if the outer script is run from Terminal, the end result is that the vendor program is launched.

I'm guessing that this is a relatively simple (but not to me) problem with the interaction between the Unix environment and the shell script.

TIA for any ideas,

Mark

Oct 6, 2010 5:59 AM in response to Mark92691

Yours:

#!/bin/bash
cd "`dirname $0`"/bin && bash datamodeler.sh $*

Change the above to

#!/bin/bash
cd "$(dirname "$0")/bin" && bash datamodeler.sh "$@"

You have spaces in your path so the dirname is failing.

Also I've replaced the $* with "$@" which as magical properties that preserve quoted call arguments.

Message was edited by: BobHarris

How to make a shell script double-clickable

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.