NSWorkSpace open File

Discussion in 'Mac Programming' started by satyam90, Aug 20, 2009.

  1. satyam90 macrumors regular


    Jul 30, 2007
    Bangalore, India
    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.

  2. kainjow Moderator emeritus


    Jun 15, 2000
    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.

Share This Page