How to run a shell script from the GUI?

This is probably a dumb question...

How do I run a shell script from the GUI? I've been told to double click it but when I do, it opens as a text file.

2.4 15" MPB, 2.2 15" MBP, 15 gb iPod 3G, iPod Shuffle, Mac OS X (10.4.6)

Posted on May 1, 2008 8:43 AM

Reply
13 replies

May 1, 2008 8:54 AM in response to BW Lee

there is no direct way to do it. you can create an apple script or an automator workflow to run it which can be then launched from GUI.

For example, make a workflow consisting of a single action "run shell script" and put the path to your shell script in there. save the flow as an application. Now, double-clicking that application will run your shell script.

May 1, 2008 9:48 AM in response to etresoft

I haven't made any term files in a long time. I just had a look and I don't even see how to do it anymore in Leopard! Darn it!

However, if you search Terminal Help for "Running shell scripts in Terminal", you will find a way to make a double-clickable file to run a script via Terminal.

charlie

May 1, 2008 12:27 PM in response to J D McIninch

that doesn't seem to work any better than .term. It depends on the app which is set to open files with a given extension, not on the extension. No matter which extension you choose, you still have to set Terminal.app to open it so any time you double-click a file, terminal will be launched.

using an apple script or an automator wrapper allows you to get rid of that.

May 1, 2008 1:55 PM in response to BW Lee

As others have suggested, you can rename the script to have a .command suffix and that will cause double clicking the script to open a Terminal window and run.

If you do not want to run the script within a Terminal window, then try using "Platypus"
<http://www.versiontracker.com/dyn/moreinfo/macosx/19870>
to put a double clickable wrapper around your script. Platypus is freeware and very nice.

If you like to roll your own, then you can use an Applescript wrapper of your own creation using the 'do shell script "..."' command. Do a google search for "applescript do shell script" and you will come up with several applicable hits.

May 1, 2008 7:14 PM in response to V.K.

The behavior you describe is that used by the KDE and GNOME desktops of Linux.

Under OS X, if you make a script then mark it as executable, double-clicking on it in the Finder will not execute it. Actually, it uses a rather complex algorithm ([summarized here|http://arstechnica.com/reviews/2q00/macos-qna/macos-x-qa-2.html]) to determine what to do with it. This is implemented in Mac OS X' LaunchServices framework (incidentally, the associations are cached in /Library/Caches/com.apple.LaunchServices*.csstore and ~/Library/Caches/com.apple/LaunchServices*.csstore). You can read the details in the developer docs about LaunchServices.

Anyway, in short, the suffix '.command' is a built-in type in the LaunchServices network that identifies a shell script. If you run

/System/Library/Frameworks/ApplicationServices.framework/Frameworks/LaunchServic es.framework/Support/lsregister -dump

... it will tell you as much.

May 1, 2008 7:40 PM in response to J D McIninch

sorry, you seem to be correct although it doesn't work for all my files for some reason. It failed on the first file I tried (it keeps opening in TextEdit) which was the reason for my post. Thanks for the education. BTW, the last command you gave me has a wrong path so it doesn't execute. Could you tell me the correct path?

Also, when I add .command to my shell scripts, when i double-click on them , it still opens a terminal window. Is there a way around that without using a GUI wrapper like apple script or automator?

May 1, 2008 8:15 PM in response to V.K.

Sorry, in Leopard, the path is now:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchSe rvices.framework/Versions/A/Support/lsregister -dump

... the previous one was for Tiger. I don't know of a way to hide the Terminal.app window, but I haven't really looked into it, I could probably think about it a while and come up with something...

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to run a shell script from the GUI?

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