Here is a shell script that will open applications from the terminal without having to type out the full path to the application. It assumes that your applications are kept in /Applications. Using this script and an alias, you can type something like "o TextEdit" to open TextEdit, or "o TextEdit ~/Documents/some_file" to open some_file in TextEdit.
If you'd like to see the script, read the rest of the article.
A good place to store these user-specific scripts is in a 'bin' directory in your user's home diretory. Your path is already set up to look there (type 'echo $PATH' to see it). If you don't have one, just create a folder named 'bin' at the same level as Documents, Movies, etc. Once you've done that (in the Terminal or the Finder), open a Terminal and 'cd ~/bin'.
The first step is to create the script. Type 'pico openApplication' (or use your favorite editor, or even TextEdit in the Finder) to launch the editor, and then paste in the following (note the first line is just a colon by itself!):
:Save your changes, making sure the script winds up in the ~/bin directory. In the Terminal, type "chmod +x ~/bin/openApplication" (this makes the script executable) and then 'rehash' (tells the shell to find new programs).
# @(#) --Opens an application if found in /Applications folder BC 10/01
APPDIR="/Applications/"
SUFX=".app"
APPNAME=$1
if [ -e $APPDIR$APPNAME$SUFX ]
then
#if there is more than one argument assume that it is a file to be opened
if [ $# -gt 1 ]
then
shift
echo found $APPNAME$SUFX
echo Attempting to Open application along with $# Files
open $APPDIR$APPNAME$SUFX $*
else
echo found $APPNAME$SUFX
echo Attempting to Open application
open $APPDIR$APPNAME$SUFX
fi
else
if [ $# -eq 0 ] #if no arguments were given show proper usage
then
echo
echo usage openApplication applicationName [ filename1 filename2 ... ]
else # Show some stuff to help out
echo
echo $APPNAME Not found in /Applications Folder
echo
echo Capitalization is Important!!
echo
echo Do not add .app to the Name, I\'ll do it for you
echo
echo Here is a list of applications in your /Applications folder
echo
echo /Applications/*.app
fi
fi
alias o `openApplication`Of course if you are already using 'o' as an alias for something else, choose another shortcut letter. To see what aliases you are using, type 'alias' with no arguments and hit enter. Once you've put the alias in the aliases.mine file, close and open the Terminal. Now you have the command 'o' at your disposal in any Terminal window.
o TextEdit--will open TextEdit
o TextEdit ~/Documents/note.txt--will open the document note.txt with TextEdit. You can add as many files as you wish, if a filename has a space in it enclose the filename in quotes.
Mac OS X Hints
http://hints.macworld.com/article.php?story=20011110021644624