Open Files from Command Line on OS X
I'm as much of a fan of application UIs as anyone else but I'm finding myself working more and more from the command line lately. Much of that is becoming obsessed with media manipulation but I'm forcing myself to use less UIs so that I can understand what's under the hood of my favorite utilities.
One common case for running any app is opening an existing file, like an HTML file in a browser or a document in Pages. To open a file on Mac OS X from the command line, type the following:
open portrait.png
The above does not specify an app to open the given file in -- the default app for that file type will be used. To open a file in a specific app, use the -a
argument:
open -a /Applications/Firefox.app portrait.png
You can also open a URL directly from the command line:
open https://davidwalsh.name/
You'd expect opening a file from command line to be easy and I'm happy to confirm to you that it is.
![How to Create a Twitter Card]()
One of my favorite social APIs was the Open Graph API adopted by Facebook. Adding just a few META tags to each page allowed links to my article to be styled and presented the way I wanted them to, giving me a bit of control...
![Convert XML to JSON with JavaScript]()
If you follow me on Twitter, you know that I've been working on a super top secret mobile application using Appcelerator Titanium. The experience has been great: using JavaScript to create easy to write, easy to test, native mobile apps has been fun. My...
![Pure CSS Slide Up and Slide Down]()
If I can avoid using JavaScript for element animations, I'm incredibly happy and driven to do so. They're more efficient, don't require a JavaScript framework to manage steps, and they're more elegant. One effect that is difficult to nail down with pure CSS is sliding up...
![CSS calc]()
CSS is a complete conundrum; we all appreciate CSS because of its simplicity but always yearn for the language to do just a bit more. CSS has evolved to accommodate placeholders, animations, and even click events. One problem we always thought...
I was just wondering how to do this, thanks!
When you use
-a
, you don’t need to write the path.…would do the same. :)
The
-a
handler is great when you want to open some program one doesn’t really know (eg remember) exactly where it is.Like:
// that one is in /System/Library/CoreServices