Launch Terminal commands via Finder filenames

Feb 26, '03 08:27:00AM

Contributed by: Anonymous

You can create a 2-line text file that, when launched in the Finder, will run the command that is the name of the file in the Terminal app. Using your favorite Unix editor create a file containing:

    #! /bin/bash
    exec $(echo ${0##*/} | tr ':' '/')
and save the file named, say, ls /Users/paul. After quitting the editor, in a Terminal window, do a:
    % chmod +x ls\ \:Users\:pjl
(Mac OS X substitutes colons for slashes in the Terminal, and they need to be escaped with backslashes)

In the Finder, do a Get Info on the file and change the Open With application to Terminal. Now double-clicking the file in the Finder will create a new Terminal window and run the command ls /Users/paul in it.

If you want to change the command, simply rename the file in the Finder. I use this for ssh machine so I can ssh to various machines. If you want several such commands, simply duplicate the file in the Finder and rename it. The contents of the file never need to change.

Comments (10)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030219232832976