Paweł Hajdan
Paweł Hajdan

Reputation: 18542

Is there an equivalent of Mac OS X "open" command that can be called from C++/Objective-C code?

On Mac OS X there is a very useful "open" command which launches an application suitable for opened file type. Is there some C++/Objective-C function on Mac which does the same?

Note: I know I could launch an "open" process. I'm just not sure if it's the best option.

Upvotes: 3

Views: 264

Answers (1)

Yuji
Yuji

Reputation: 34185

That is done by NSWorkspace. See -[NSWorkspace openFile:]. All you have to do is

[[NSWorkspace sharedWorkspace] openFile:@"file.txt"]

If you want more fine-grained control (e.g. getting all applications which can open a given file,) you use Launch Services. See the document and the reference.

Upvotes: 4

Related Questions