views:

4855

answers:

7

I'm sure the answer is ridiculously obvious, but so far Google hasn't been very helpful. How do I set up a shell script to execute from the dock? It seems that simply creating a shortcut will open the file in my editor. Is there a flag I need to set somewhere to tell it to run instead of opening it for editing?

+3  A: 

I think this thread may be helpful: http://forums.macosxhints.com/archive/index.php/t-70973.html

To paraphrase, you can rename it with the .command extension or create an AppleScript to run the shell.

Abyss Knight
+4  A: 

If you don't need a Terminal window, you can make any executable file an Application just by moving example.sh to example.sh.app/Contents/MacOS/example.sh. You can place the Application in your dock like any other, and execute it with a click.

If you do need to have the terminal window displayed, I don't have a simple solution. You could probably do something with Applescript, but that's not very clean.

Jeremy Banks
+1  A: 

Perhaps this method will help Wrapping a Command Line Application with a GUI Interface

Michael Glenn
A: 

As long as your script is executable and doesn't have any extension you can drag it as-is to the right side (Document side) of the Dock and it will run in a terminal window when clicked instead of opening an editor.

If you want to have an extension (like foo.sh), you can go to the file info window in Finder and change the default application for that particular script from whatever it is (TextEdit, TextMate, whatever default is set on your computer for .sh files) to Terminal. It will then just execute instead of opening in a text editor. Again, you will have to drag it to the right side of the Dock.

Jason Coco
+17  A: 
dbr
@dbr, GUI button pusher! :) Just kidding, that is a good suggestion!
Abyss Knight
Yeah, it was an excellent suggestion :) I've even written Automator actions for some of my apps and I still forget about it in times like this :)
Jason Coco
Perfect. Thanks!
Jeremy Ricketts
I can't get this to work with nohup, a la "nohup /usr/bin/myscript
Ali Nabavi
dbr
Can't get this to work... My simple script: R CMD Sweave $1 | pdflatex | open
ran2
+1  A: 

In the Script Editor:

do shell script "/full/path/to/your/script -with 'all desired args'"

Save as an application.

As long as all you want to do is get the effect of the script, this will work fine. You won't see STDOUT or STDERR.

Joe McMahon
I would suggest: "Save as an application BUNDLE". The bundles launch much faster than applications.
e.James
+1  A: 

I know this is old but in case it is helpful to others:

If you need to run a script and want the terminal to pop up so you can see the results you can do like Abyss Knight said and change the extension to .command. If you double click on it it will open a terminal window and run.

I however needed this to run from automator or appleScript. So to get this to open a new terminal the command I ran from "run shell script" was "open myShellScript.command" and it opened in a new terminal.

Jason Tholstrup