3 Answers
3

The simple, but completely fallible, approach is to just write a shell script. Save this to a file called mysay.sh:

#!/bin/sh
say hello world
say number five is alive

As long as you don't have XCode installed that should open up in Terminal when you double click on on it.

You can also do this with AppleScript and it's a little more durable since you don't have to worry if the default application for .sh files isn't Terminal:

tell application "Terminal"
set currentTab to do script "/usr/bin/say hello world"
do script "/usr/bin/say number five is alive" in currentTab
end tell
delay 5
tell application "Terminal" to quit

Save that as an Application from the AppleScript Editor and you can double click on it and your Mac will talk to you. You can wait and close the Terminal session afterwards with a little more AppleScript if you like.

I followed the second method and saved it to my desktop and it runs perfectly. However, if I try emailing it to myself and then opening the downloaded it file it gives the error message that I can't open it because "the Classic environment is no longer supported". Any idea how to solve this?
–
negatronApr 22 '12 at 22:04

I'm using gmail. If I use the Console force Script Editor to open the downloaded file I get this error message: Unable to read the dictionary of the application or extension because it is not scriptable.
–
negatronApr 23 '12 at 10:30

You can also do this with AppleScript as mentioned above, by Ian C. However, you can do the single command in fewer lines, and with a delay. Here is an AppleScript which will run the command, then wait 5 seconds, and then quit the terminal.

Just an alternate method, compared to @Ian C.'s way. You could also take Ian's .sh file, and rename it .command if you do have XCode, which will open it in Terminal, and do the same thing as the AppleScript, just without the delay. Hope this helps.

That's all really helpful, thanks so much. Is there any way to include the execution rights within the shell script itself (so that if I email it to someone, it works straight away without them having to run chmod u+x ?
–
negatronApr 23 '12 at 11:13

@negatron haha, no, its a chicken-egg style thing, you need execution rights to run the script; and if you want the script to give itself execution rights you have to run it. Besides, imagine how easy it would be to infect machines if you didn't need to grant execute rights; there's a reason they exist in the first place.
–
HawkenApr 23 '12 at 21:33