open a document through the finder

Discussion in 'Mac Programming' started by bengut, Jul 21, 2011.

  1. bengut macrumors newbie

    Jun 15, 2011
    When a*user double clicks a document in the finder and the finder launches the preferred application to open this document, how does that preferred application get to know to handle this event.

    I red the "launcheServicesConcepts" but I understand this is only for the case when I want to launch another application from within my own application

    Can anyone help ?


  2. bengut thread starter macrumors newbie

    Jun 15, 2011

    Thanks kpua, but I think NSWorkspace doesn't help.
    My app need somekind of notification from the finder that it should open a document. So my app can verify, whether it can handle the type of document or not. But which notification ?

    Does anyone know ?

  3. jiminaus, Jul 21, 2011
    Last edited: Jul 21, 2011

    jiminaus macrumors 65816


    Dec 16, 2010
    According to the Open Operations section of the Launch Services Programming Guide (, your app be sent an odoc Apple event instructing it to open the specified document.

    There's an NSApplicationDelegate method called application:openFile: ( The docs don't say under what circumstances this delegate method is called, but perhaps try implementing it to just do an NSLog in order to see if it gets called.

    If it doesn't get called, perhaps you might need to handle the Apple event yourself. But my gut says the Cocoa framework would be doing this for you.

    EDIT: According to the Cocoa Scripting Guide (, you should override application:openFiles: ( in your app delegate. That's files plural, not file singular.
  4. bengut thread starter macrumors newbie

    Jun 15, 2011
    Bingo jiminaus :)
    I tried your proposal and implemented application:openFile: . First it wasn't called , but then I connected the Files Owner Outlet delegate to myAppController Class in Interface Builder and now the delegate is called. Just great . Now I have to verify the "filenames". By the way this is the 2nd time you helped me. I come back to you later. Regards from Berlin, Germany
  5. bengut thread starter macrumors newbie

    Jun 15, 2011
    Hi jiminaus, thanks again for your tip. It was a hit.
    NSApplication calls its delegate "openFiles" and passes an Array of Strings with the dedicated filenames (full path). Then you can proceed to initiate those files.

    There is another delegate called "applicationOpenUntitledFile". When you for instance click the app icon in the dock and there is no document open in your app, then NSApplication calls this delegate to open a new one.

    regards from Berlin Germany
  6. bengut thread starter macrumors newbie

    Jun 15, 2011
    QTMovieCurrentSizeAttribute need help

    Here is a passage of the QTMovie Class Reference about an attribute
    The current size of a QTMovie object; the value for this key is of type NSValue, interpreted as an NSSize structure.
    This attribute can be read and written. This attribute cannot be read or written when the movie has been initialized with QTMovieOpenForPlaybackAttribute set to YES. This attribute is deprecated in QTKit version 7.6 and later.
    Does anyone knows if there is a successor for this attribut.
    Or how can one retrieve the current movie size when the window resizes and the movie view size grows or shrinks accordingly

    bengut from Berlin

Share This Page