Guest User

Untitled

a guest
Jun 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. - (void) setupAppFrontSwitchedHandler
  2. {
  3. EventTypeSpec spec = { kEventClassApplication, kEventAppFrontSwitched };
  4. OSStatus err = InstallApplicationEventHandler(NewEventHandlerUPP(AppFrontSwitchedHandler), 1, &spec, (void*)self, NULL);
  5.  
  6. if (err)
  7. NSLog(@"Could not install event handler");
  8. }
  9.  
  10. - (void) appFrontSwitched {
  11. NSLog(@"%@", [[NSWorkspace sharedWorkspace] activeApplication]);
  12. }
  13.  
  14. static OSStatus AppFrontSwitchedHandler(EventHandlerCallRef inHandlerCallRef, EventRef inEvent, void *inUserData)
  15. {
  16. [(id)inUserData appFrontSwitched];
  17. return 0;
  18. }
  19.  
  20. // NSWorkspaceDidActivateApplicationNotification
  21. [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(foremostAppActivated:) name:NSWorkspaceDidActivateApplicationNotification object:nil];
Add Comment
Please, Sign In to add comment