title: Fetching Global Events and Notifications in command line application with swift
body: <p>I have a command line application and I would like to receive global mousemove and keypress events as well as some notifications. However this will not work. The console Application does have accessibility rights when started.</p>
  <p>There is no error printed but it simply does not work. What could be the issue?</p>
  <p>The Notification is working while the NSEvent is not working.</p>
  <pre><code>NSEvent.addGlobalMonitorForEvents(matching: NSEvent.EventTypeMask.keyDown, handler: logEvent)
  NSEvent.addGlobalMonitorForEvents(matching: NSEvent.EventTypeMask.mouseMoved, handler: logEvent)
  NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(logNotification), name: NSWorkspace.willSleepNotification, object: nil)
  NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(logNotification), name: NSWorkspace.willPowerOffNotification, object: nil)
  NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(logNotification), name: NSWorkspace.screensDidSleepNotification, object: nil)
  NSWorkspace.shared.notificationCenter.addObserver(self, selector: #selector(logNotification), name: NSWorkspace.sessionDidResignActiveNotification, object: nil)
  
  @objc dynamic func logEvent(_ incomingEvent: NSEvent?) -&gt; Void{
      print(&quot;here was a keypress or mousemove &quot;)
  }
  
  @objc dynamic func setInactive(aNotification : NSNotification){
      Log(&quot;Event was called &quot; + aNotification.name.rawValue)
  }
  </code></pre>