[HOWTO] Run command line apps/scripts from Finder or an AppleScript

MikeDC

Registered
Hi, I am very new to MacOSX but I was wondering if there was a way to make applications that run from the terminal work as double-clickable applications? Is there an OSX version of a Windows batch file, ie something that can be double clicked and will execute terminal commands?
 
Glad you asked! I can tell you at least one way.

First, you CAN write Unix shell scripts & run them with OSX - and these are very much like DOS batch files, but personally, I don't know of a way to put those directly on the desktop.

But there is another scripting tool called AppleScript. Search your HD for an app called "Script Editor" - this is used to create and modify AppleScript programs.

There is an applescript command that goes:

do shell script "insert unix command here"

You can put in any UNIX command line commands you want.

Then you can "Save As Application" from the File menu, and you're off and running. You'll get an application icon that can be parked in the Dock, the desktop, or wherever you like.
 
Adding to brianleahy's comment - AppleScript is indeed an easy way to run shell scripts, and you don't even need to save them as applications. Inside the Applications>AppleScript folder you'll find a little doohickey called ScriptMenu.menu which provides a dropdown menu in the system menu bar. You can run any compiled script from there by placing it in a 'Scripts' folder in your own Library folder or the top level Library folder on your startup disk.

For up to date info on including shell scripts in AppleScripts, check out Apple's recent TechNote TN2065 on this subject at http://developer.apple.com/technotes/tn2002/tn2065.html
 
there's a small program - Mac scriptGUI - that will
turn a script into a double-clickable applications
or a droplet

search on Google for:Mac scriptGUI
 
It is much easier , like fokman, three posts before, points out! You don't have to use apple script at all. just make a script in your favourite text editor and save it with the .command extension.

When you doubleclick this script, it will open a terminal and run your script..

NOTE! when using BB-edit you have to change the options settings in the save as menu:
Save State should be set to MPW Shell
Line breaks -> Unix ( i'm not sure if this is nessesary, i just put it that way).
If you keep the default settings you'll find that BB-edit opens the file when you doubleclick it.
 
However, if you use AppleScript, Terminal doesn't activate, and you don't get extra Terminal windows cluttering your display. This might be useful sometimes.
 
Back
Top