Starting a default program in OSX programmatically
How d开发者_JAVA百科o I start XCode (or any other default program associated with a file) and make it open a specific file programmatically? Similar to double-clicking a .c in Finder - it opens an XCode editor with the file.
There is a method called openFile:
on NSWorkspace
that does exactly this.
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html
(For bonus points, if you want to do it from the shell, you can use the open
command.)
Running open your-file.ext
from a shell or a shell script will cause the Finder to open the file in the default associated app, as if you had double-clicked it.
man 1 open
for more info on how open works.
精彩评论