[robg adds: After some email conversations with discordantus, we've figured out why this worked for him and wouldn't work for me, hence the following qualifications on this hint:
- You absolutely must include the #! line at the top of your script, ie #! /bin/sh. If you don't, it thinks it's an AppleScript applet. It depends on this line to tell it what shell to run the script in.
- If you don't set the executable bits (chmod a+x filename), it'll show up, but fails to run (completely without notice) when you choose it from the menu.
- When the script menu reloads itself, it seems to just scan its folder for any new or missing files. It doesn't check to see if the actual contents of the files have changed. So you may need to remove the menu and relaunch it to see some changes.
- When you run a script via the script menu, it seems to effectively redirect the STDOUT (standard output, ie the Terminal window in most cases) to /dev/null. So all that output just flies out into the ether, and you don't see anything. So you'll need to redirect the script output elsewhere in order to see the results.
#!/bin/sh
#
# fetch a fortune from thinkgeek
#
curl -s http://www.thinkgeek.com/fortune.shtml | \
sed -n '/(refresh for another)/,/table\>/p' | \
sed -n '/<p>/,/<\/p>/{/[.]/p; }' | \
sed '{/^<[/]*p>/d; s/<[BbRr]*>//g; s/<\;/</g; s/>\;/>/g; }' > \
/tmp/output.txt
open /tmp/output.txt
I then copied this script from my ~/bin directory into my ~/Library/scripts directory, and ran it from the menubar. The end result was a new TextEdit window containing a random fortune from thinkgeek.com. Hopefully, you'll be able to find more useful applications of this trick, but it does demonstrate that it works!]

