Friday, May 02, 2008

open

I should have known about this before.

briandunbar_natasha-2_~/foo/foo:touch bob
briandunbar_natasha-2_~/foo/foo:open bob

Textmate launches and displays the file - slick.

briandunbar_natasha-2_~/foo/foo:touch bob.doc
briandunbar_natasha-2_~/foo/foo:open bob.doc

NeoOffice launched.

briandunbar_natasha-2_~/foo:open foo

Finder opened the directory 'foo'.

briandunbar_natasha-2_~/foo:man open
(snip)
The open command opens a file (or a directory or URL), just as if you had double-clicked the file's icon. If no application name is specified, the default application as determined via LaunchServices is used to open the specified files.

If the file is in the form of a URL, the file will be opened as a URL.

You can specify one or more file names (or pathnames), which are interpreted relative to the shell or Terminal window's current working directory. For example, the following command would open all Word files in the current working directory:

open *.doc
(snip)
EXAMPLES
"open '/Volumes/Macintosh HD/foo.txt'" opens the document in the default application for its type (as determined by LaunchServices).

"open '/Volumes/Macintosh HD/Applications/'" opens that directory in the Finder.

"open -a /Applications/TextEdit.app '/Volumes/Macintosh HD/foo.txt'"
opens the document in the application specified (in this case, TextEdit).

"open -b com.apple.TextEdit '/Volumes/Macintosh HD/foo.txt'" opens the document in the application specified (in this case, TextEdit).

"open -e '/Volumes/Macintosh HD/foo.txt'" opens the document in TextEdit.

"ls | open -f" writes the output of the 'ls' command to a file in /tmp and opens the file in the default text editor (as determined by LaunchServices).

"open http://www.apple.com/" opens the URL in the default browser.

"open 'file://localhost/Volumes/Macintosh HD/foo.txt'" opens the document in the default application for its type (as determined by LaunchServices).

"open 'file://localhost/Volumes/Macintosh HD/Applications/'" opens that directory in the Finder.

I'm a happy monkey for having discovered this. Using 'open' to launch a URL in the browser seems especially cool.
blog comments powered by Disqus