341008
341008

Reputation: 10242

How to detect if app was launched by double clicking on a file?

I need to detect if my application was launched in response to user double-clicking on a file or through Spotlight. I have to do something extra if it was invoked through Spotlight (or by double-clicking on the application icon) and don't have an input file to open. I don't have access to the NSApplicationDelegate object so I can't set a flag on applicaion:openFile(s):. In any case, I cannot wait indefinitely to check if those callbacks have happened. Is there any way I can query for the launch method from any arbitrary point in the code?

Upvotes: 2

Views: 482

Answers (1)

TheDarkKnight
TheDarkKnight

Reputation: 27631

When you double-click an application's associated file, the application is launched from Finder by a call to Apple's Launch Services, with the function call to LSOpenURLsWithRole.

Spotlight, most likely, also uses Launch Services or directly calls Finder, so I think the answer is no, you won't be able to differentiate between launching via Finder or Spotlight.

Perhaps if you give more detail on what you're trying to achieve and why you need to differentiate between them, there may be another way of solving the problem.

Upvotes: 1

Related Questions