views:

20

answers:

1

Pretty much all the apps I use on a regular basis implement this 'seemly simple' scenario, yet I can't replicate this in my own Cocoa application. Please consider these steps:

  1. The application is not running
  2. You drop a file, or a selection of files onto the app's icon.
  3. The app runs and performs some actions on the dropped files.
  4. Maybe it opens them, maybe not, but stuff happens.

When I try googling the answer, some of them even here on stackoverflow point me towards the NSApplicationDelegate's application:openFiles: method. The explanation on how to get from Apple events to the delegate is here.

With the proper UTIs in place (**), this works like a charm when the application is already running. However, since I'm trying to make a 'droplet' style application, I want it to also work when the app is not yet running.

And in this last scenario, the application:openFiles: method is not called. Right now I have only a simple NSLog() call in there, and it doesn't show (I'm looking at the Console.app, since it's kinda hard simulating a dropped file on build in XCode).

Can someone tell me where to look, what to do, what to change?

Cheers, Eric-Paul.

+1  A: 

This is actually really rather simple: The application is likely not registered with launch services. Try installing it in your Applications folder, and see if that helps.

Williham Totland
I'm not sure I understand this mechanism, but it indeed works now!
Eric-Paul
When you add an application to ~/Applications, /Applications or /Developer/Applications (and possibly a few other folders, and subfolders, Launch Services kicks in and reads the Info.plist, and not before. This causes stuff like dragging and dropping to work correctly even when the application is closed.
Williham Totland
There is a tool called lsregister inside the Launch Services framework bundle that you can use to manually register any application. (Not to be used programmatically, of course. For debugging purposes only.)
Peter Hosey