Project 98. Open Aqua Items"How do I open a Mac OS X application from the command line?" This project is all about the open command. It's the command-line equivalent of double-clicking, used to open files and folders and to launch Mac OS X graphical applications. Learn More
Open a FolderTo open a folder into a Finder window from the command line, use the open command, passing the name of the folder. Open your Documents folder, for example, by typing $ open ~/Documents Tip
A Finder window opens, showing the contents of your Documents folder in Icon view. Although this command is not very useful on its own, you could use open in a script to open a set of commonly used folders or as part of another command. You could search for folders named backup and open them all in a single command by typing $ find ~ -type d -iname backup -print0 | xargs -0 open Make a commonly used and deeply nested folder the subject of an alias for quick and easy opening. $ alias archive="open ~/Documents/101/Chapter11/archive" Open an ApplicationThe open command simulates a double-click action and can be used to launch any of the applications in the /Applications directory. To launch Calculator, type $ open /Applications/Calculator.app An application written to Apple's guidelines is part of a package. Although it looks like an application icon in the Finder, a package is really a folder with a .app extension. The executable itself is located within the package, as are other resources, including the application's icon, displayed instead of the usual blue folder icon. Explore a package such as /Applications/Calculator.app: You'll find the executable code in the subdirectory Contents/MacOS/Calculator. Learn More
Older (Carbon-based) applications are not implemented as Mac OS X packages and don't have an .app extension. If, for example, your publishers were to insist that you use Microsoft Word, launch it by typing $ open "/Applications/Microsoft Office X/Microsoft Word" The open command will launch an application's executable directly if you specify the -a option. To launch the Calculator executable instead of double-clicking its package, type $ open -a /Applications/Calculator.app/¬ Contents/MacOS/Calculator
An executable can also be launched directlywithout using open -ajust like a Unix command. (Remember to launch it as a background job so that it returns control of the Terminal immediately.) $ /Applications/Calculator.app/Contents/MacOS/Calculator & [1] 22820 $ Tip
This technique does not work for Carbon-based applications such as Microsoft Word, because the executable is not in the native format required by Mac OS X. Although you'd probably use open to launch such an application, here's how to launch its executable directly. $ /System/Library/Frameworks/Carbon.framework/Versions¬ /Current/Support/LaunchCFMApp ¬ "/Applications/Microsoft Office X/Microsoft Word" & Short and snappy! Open a FileThe open command can be used to open a document in the default application for the document type. To open a screen shot that has the extension .png, in the default application Preview, for example, type $ open ~/Desktop/Picture\ 1.png Note
You may use wildcards, of course, to open multiple files. $ open *.png Tip
Like double-clicking, open uses Launch Services to determine which application to launch to open a document. To have a document open in an application other than the default, specify the -a option, and name the application. To open the same screen shot in Adobe Photoshop 7 instead of Preview, type $ open -a "/Applications/Adobe Photoshop 7/¬ Adobe Photoshop 7.0" ~/Desktop/Picture\ 1.png A handy option, -f has open read text from its standard input, or a pipe, and open the text in TextEdit. To open this year's calendar using the cal command covered in Project 96, type $ cal -y | open -f Alternatively, specify an application other than TextEdit. $ cal -y | open -a "/Applications/Microsoft Office X/¬ Microsoft Word" -f Open URLsTry the following commands, which demonstrate that open understands URLs. $ open ftp://ftp.apple.com $ open http://www.apple.com You can even connect to a server. To mount an AFP share called saruman from a host called carcharoth, for example, type $ open afp://carcharoth/saruman |