When a macOS application is already open and running, is there any way for it to detect when its Finder icon is opened?
In that situation, opening its Finder icon causes the application to become active, and I can detect that event using NSNotificationCenter
or the application delegate's applicationDidBecomeActive:
method.
However, so far I haven't found a way to distinguish that activation event from any of the other ways an application can become active, such as clicking on its window, clicking on its Dock icon, switching to it using command+tab, activating it with AppleScript, and so on. I tried checking to see if any of these circumstances used an apple event to activate the app with [[NSAppleEventManager sharedAppleEventManager] currentAppleEvent]
, but it returns nil as there is no current apple event, so that doesn't help.
The app delegate method -applicationShouldHandleReopen:hasVisibleWindows:
is called on such a re-open event.
Note that (re-)opening from the Finder, Launchpad, or Dock is the same, by design.