How can i make this shell script run just by double clicking on it?

I have a shell script that i want to be able to just double click on to run. The script will back up user data before netrestore runs. I tried to do run shell script in apple script, but there are to many spaces and commands it dose not like. Any ideas???

#!/bin/sh

sudo chmod -R 777 “/Volumes/Macintosh HD/Users”

ditto -c -z “/Volumes/Macintosh HD/Users” “/Volumes/Storage/bk.cpgz”

open -a “NetRestore”

You should be able to save the shell script in your user directory, add that path to your shell profile, and then make a short applescript that calls your shell script:

do shell script "yourShellScript.sh"

Once you have that working, save the AS script as an application, and double click it anytime.

For more details, check out some of the UNIX links on the links page: http://macscripter.net/links/

This is also nicely explained in a recently published book on UNIX for the Mac:

http://macscripter.net/books/reviews/65_0_1_0_C/

Hi,

Another way to do this might be to make a shell script runner. I’m not thinking right now, but it’s something like this. You use the Finder to direct your file to open with a shell script runner. You set the open with by get info in the finder and browse to choose a stay open script (AppleScript app). The AppleScript app might look something like this:

on open p
	set t to read p
	do shell script t
	set r to result
	display dialog r
end open

When you double click on your unix script which is set to open with this app, the Finder sends a reference of your unix text file to this app. The variable p (editted: changed t to p) is the reference and your script app reads the text file. It then do shell script the text. I don’t know why it’s not working now. The script app should display the result of the unix scipt. This is an offshoot of running compiled script from the dock.

Comments from anybody is welcome.

Later,

It worked! My unix script was bad. :stuck_out_tongue:

BTW, it’s best to create the script runner as a stay open app. When you run your files it is almost instantanious.

If you’d like to see Terminal when you’re script is run, you could rename your file so that is ends with “.command” (instead of .sh, or whatever you’re using).

Why not change this.

set r to result
display dialog r

.to this:

display dialog result

Also, would you please use AppleScript tags when posting code (see this page).

Hi Bruce,

The reason why I don’t use the AppleScript post is because it doesn’t work in Jaguar when opening it back up in the Script Editor. If I copy back from the tagged script and paste it into The Script Editor, that doesn’t come out right especially on with long scripts. I tried it before, but will do it if it is important.

gl,