Building an Agent or Daemon on macOS to Monitor File Uploads, Drag-and-Drop, Clipboard, and Keystroke Events

Hello everyone,

I'm interested in creating an agent or daemon on macOS that can monitor several types of user interactions:

File Upload Events: I want to listen for events when users upload files to their Macs.

Drag-and-Drop Events: I'd like to capture events when users perform drag-and-drop actions.

Clipboard Events: I'm also interested in monitoring copy/paste actions in the clipboard.

Keystroke Events: Finally, I want to be able to track keystroke events.

Could anyone provide guidance or point me in the right direction on how to achieve this? Any help or resources would be greatly appreciated.

Thank you!

This is a very tall order. I suspect that it’ll be impossible to meet all of your goals.

To start, you’ll likely need a daemon and an agent, because some of these things can only be done from a daemon and some can only be done from an agent.

File Upload Events: I want to listen for events when users upload files to their Macs.

Please specify what you mean by “upload”. I presume that this includes uploading using a web browser. What about copying a file to an SMB file server?

Drag-and-Drop Events: I'd like to capture events when users perform drag-and-drop actions.

I’m not aware of any way to do this.

Clipboard Events: I'm also interested in monitoring copy/paste actions in the clipboard.

There are techniques for doing this, all based on NSPasteboard. Reading the pasteboard is easy; the hard part is knowing when to read it. I’m not sure what best practice is here, but I think that most folks just poll the changeCount property.

This needs to use AppKit and thus has to run as an agent.

If you need more info, I recommend that you start a new thread for this specific topic and tag it with AppKit.

Keystroke Events: Finally, I want to be able to track keystroke events.

I generally use CGEventTap for that. You can find a snippet here.

Again, this needs to run as an agent.

If you have follow-up questions, I recommend that you search DevForums because this is something I’ve talked about extensively here. If you don’t find the answers you seek, start a new thread and tag it with Core Graphics and Privacy.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Building an Agent or Daemon on macOS to Monitor File Uploads, Drag-and-Drop, Clipboard, and Keystroke Events
 
 
Q