5

Is there a way to report every mouse click on the application dock icon?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134

2 Answers2

9

Not completely safe (also activated by double-click on the application itself),
but definitely the most easy way to implement:

- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag

Quote from NSApplicationDelegate Protocol Reference:

These events are sent whenever the Finder reactivates an already running application because someone double-clicked it again or used the dock to activate it.

Anne
  • 26,765
  • 9
  • 65
  • 71
1

I would like to suggest an alternative solution to the answer provided by Anne, which avoids conflicting with the event in which the user double clicks on the application icon, instead of on the dock icon.

Thus, I suggest to use

- (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender;

See also the Apple's documentation.

Andrea Alberti
  • 186
  • 1
  • 9