Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何启动 XCode(或与文件关联的任何其他默认程序)并使其以编程方式打开特定文件?与在 Finder 中双击 .c 类似 - 它会打开带有文件的 XCode 编辑器。
有一个方法openFile:可以NSWorkspace做到这一点。
openFile:
NSWorkspace
http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/NSWorkspace_Class/Reference/Reference.html
(对于加分,如果你想从 shell 做,你可以使用open命令。)
open
从 shell 或 shell 脚本运行open your-file.ext将导致 Finder 在默认关联的应用程序中打开文件,就像您双击它一样。
open your-file.ext
man 1 open
有关 open 如何工作的更多信息。