View Full Version : NSWorkSpace open File

Aug 20, 2009, 09:46 AM
I am using Cocoa with Obj C.
I am using the following method to open a file associated with a particular application.
[[NSWorkspace sharedWorkspace] openFile:<some file path>]
But if the file is associated with certain application, it is opening.

If the file is not associated with any application, I want the user to select the application also with which the file has to be opened. In the following code we have to tell which application it has to open.
[[NSWorkspace sharedWorkspace] openFile:< some file path> withApplication:@"TextEdit"]

But I want user to select the application at run time dynamically.


Aug 20, 2009, 10:57 AM
You can probably use LSCopyApplicationURLsForURL() (or one of the other Launch Services functions) to determine if there already is a default app to open it. If that returns empty, use NSOpenPanel to let the user select an app.