Tuesday Tool :Opening files from the command line in TextEdit

Any serious OSX developer is going to end up spending time on the command line solving some problems. To that end here is several example of how to use open:


To open a file as if you had double clicked in the finder, use this command. This will open myfile.jpg in the default jpg viewer.

open myfile.jpg

Many time you find yourself with a file that you want to open in a specific application. For this you can use the -a flag. This will work if the application is in a well known place. If the application is not in a well known place you can use the entire path to the application.

open -a Safari myfile.jpg
open -a /MyAdobeApps/Photoshop.app myfile.jpg

As shorthand for TextEdit, just use the -e file

open -e README.1st

If you have a program that generates output, you can pipe the results to open and have it show in TextEdit.

cal | open -f

And finally, you can also use this to open directories in Finder:

open .
open ~/Desktop

This entry was posted in Tools. Bookmark the permalink. Follow any comments here with the RSS feed for this post. Both comments and trackbacks are currently closed.
  • iChat Status