-1

I am wondering if there is a way to monitor when a user presses open file (cmd+o) in any application.

I was thinking I could use addGlobalMonitorForEvents, but I was not sure how to get the specific on "Open File..." event.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
zoecarver
  • 5,523
  • 2
  • 26
  • 56

1 Answers1

0

I was able to mostly solve the problem by using this answer:

    let keycode = UInt16(0x1F)
    let keymask: NSEvent.ModifierFlags = NSEvent.ModifierFlags.command
    //...
    let options = NSDictionary(object: kCFBooleanTrue, forKey: kAXTrustedCheckOptionPrompt.takeUnretainedValue() as NSString) as CFDictionary
    let trusted = AXIsProcessTrustedWithOptions(options)
    if (trusted) {
        NSEvent.addGlobalMonitorForEvents(matching: .keyUp, handler: self.handler)
    }
Eric Aya
  • 69,473
  • 35
  • 181
  • 253