Convrt is a small open-source menu bar app: you start dragging files from Finder or the desktop, hold Shift, and a wheel opens under the cursor. Drop on a slice and the file is converted (HEIC to JPG, MOV to MP4, images to PDF and so on).
The interesting part isn't the conversion. It's how a background app with no window finds out that some other app is dragging files and that Shift is down, without breaking the drag. Here is how it works in the shipped code.
1. Watch mouse and modifier events globally
A menu bar app never gets these events directly, so it uses a global monitor:
let mask : NSEvent . EventTypeMask = [ . leftMouseDown , . leftMouseDragged , . leftMouseUp , . flagsChanged , . scrollWheel , . keyDown ] monitor = NSEvent . addGlobalMonitorForEvents ( matching : mask ) { [ weak self ] event in self ? .…