NSWorkSpace open File

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

  1. macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #1
    I am using Cocoa with Obj C.
    I am using the following method to open a file associated with a particular application.
    Code:
    [[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.
    Code:
    [[NSWorkspace sharedWorkspace] openFile:< some file path> withApplication:@"TextEdit"]
    But I want user to select the application at run time dynamically.

    --Satya.
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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