If you want a shell script to be executable from Finder then you only need to follow two steps. No additional helper apps are needed; some exist but don't bother.
When the file.command is double-clicked/command-o in Finder, the Terminal will pop up and you'll see the script executed as well as the output.
Note 1: It does not work to symlink a current .sh script and make the symlink end in .command
Here's an example script I use to mount my code repository since I'm having trouble with AutoFS caching and failing to reconnect.
Example File: code_repos.command
#!/bin/sh sshfs adam@svn:/path/to/code_repos/ /Users/adam/ssh_mounts/code_repos -oreconnect,volname=code_repos
Example Terminal.app Output
Last login: Thu Feb 21 01:27:22 on ttys003 You have mail. /Users/adam/Desktop/Scripts/sshfs/code_repos.command ; exit; mosfet:~ adam$ /Users/adam/Desktop/Scripts/sshfs/code_repos.command ; exit; logout [Process completed]
Note 2:
Wherever you put the file, it will run with your home directory (ie: /Users/adam) as the current working directory.
To get around this, use the following line after the #!/bin/sh in your shell script. This will move the current working directory to the directory that contains your command file.
cd "`dirname "$0"`"
Comments
Anonymous (not verified)
Sun, 08/03/2008 - 12:36
Permalink
Exactly...
Exactly what I was looking for...Thanks! barrettmo
Anonymous (not verified)
Tue, 08/17/2010 - 08:18
Permalink
Exactly what I was looking
Exactly what I was looking for...Thanks! barrettmo http://www.oyunyolu.net/" title="oyunlar">Oyunlar
Anonymous (not verified)
Thu, 01/29/2009 - 06:40
Permalink
If you want to use the
If you want to use the script on the command line as well as through Finder a nicer way to change the working directory is replacing cd with pushd and adding a popd command at the end of the script. I know this works for at least bash (not sure about others) and it leaves the user's directory intact when running from the command line.
Anonymous (not verified)
Mon, 08/03/2009 - 22:42
Permalink
closing window
Thank you for your post. I was trying to get my window to close after the script has run. My script is run on startup and doesn't require any user interaction. I read several other posts that mention AppleScript or a preference in the Terminal app, but I have not had any luck yet.
Anonymous (not verified)
Fri, 07/09/2010 - 23:03
Permalink
http://www.herve-leger-sale.org
Cheap herve leger sale online, provides hundreds of fashion h which is a professional Herve Leger Shop. These are so wonderful. Many women are attracted by the noble of herve leger dresses.
Anonymous (not verified)
Tue, 10/05/2010 - 01:45
Permalink
NFL Jerseys
well,the following i will do a introduce about the popular jerseys:
Anonymous (not verified)
Wed, 11/03/2010 - 13:11
Permalink
Axis33
Thank you! Well explained. :)
Anonymous (not verified)
Tue, 05/10/2011 - 11:41
Permalink
thanks!
Damn - I've been wanting to make my scripts executable for others not so adept at running stuff on the command line for ages! Thanks for this!