Inspired by the last comment on this hint, I created the ultimate (to me, at least) command-line application launcher.
Using my solution, I can now launch GUI apps from the command line, complete with Tab completion. For instance, I type iMov[Tab][Enter], and iMovie HD launches; iTu[Tab][Return] for iTunes, etc.
Here's how I did it. First, I created an Apps directory in my user's home directory, and added it to the $PATH variable. Then I placed the following script in the new Apps directory. I named it generatelinks.sh and made it executable with chmod a+x generatelinks.sh:
#!/bin/sh
cd ~/Apps
find -E /Applications/ -regex ".*\.app$" -print |
while read APPS; do
APPLINK=`echo -n "$APPS" | sed s:".*/":"": | sed s:" ":"__":g`
echo $APPLINK
ln -s open.sh "$APPLINK"
done
I then ran the script, and it generated a link for each application in /Applications to the following script in the same Apps directory. This one is named open.sh, and again, remember to chomd a+x open.sh to make it executable:
#!/bin/sh
APP=`echo -n $0 | sed s:"__":" ":g | sed s:".*/":"": | sed s:".app":"": `
echo $APP $1
open -a "$APP" $1 $2 $3
Once the generatelinks.sh script has run, you're done -- you can now launch anything in /Applications by just typing a portion of its name and hitting Tab then Return. I'm sure it could be done with more efficient sed stuff (comments welcome!), but ... it does the trick for me, and as I'm not writing shell scripts every day...
find -E /Applications/ /Volumes/Apps/Utils -regex ".*\.app$" -print |
Finally, if you change the open.sh script name, make sure you change the reference in generatelinks.sh, too.]
Mac OS X Hints
http://hints.macworld.com/article.php?story=20051029042549279