9 ms·
Another question - I've looked before for any documentation on building tools for Mac, and can't really figure out anything besides "run this xyz app to trigger
by blueberrychpstx 4y ago
Another question - I've looked before for any documentation on building tools for Mac, and can't really figure out anything besides "run this xyz app to trigger an AppleScript and do magic".
Does anyone know of any Swift APIs for interacting at the level of the OS itself?
- lelandfe 4y agoscriptingosx[0] is a great resource, here's a simple Swift command line tool they wrote that might be a good reference: https://github.com/scriptingosx/desktoppr https://github.com/scriptingosx/desktoppr [0] https://scriptingosx.com/ https://scriptingosx.com/
- philsnow 4y agoWould Hammerspoon fit your use case? It lets you write lua to interact with all kinds of system APIs. It's roughly the first thing I install on a new mac.
- bobbylarrybobby 4y agoIf you want to put together keyboard-shortcut-triggered automations on a Mac without any third party software, I think you have to create an automator service and then assign it a shortcut in System Preferences > Keyboard > Services. I know you asked about Swift, but... If you're ok with third party software, I would recommend keyboard maestro. In addition to triggers (keyboard-based and others), it offers a pretty high level API over the macOS automation stuff you'd typically hack together with AppleScript, such as "activate app", "bring window at index i to front", "simulate keystroke", "insert text", "move the mouse to x,y relative to Element", "run JS in frontmost browser tab", etc. And that's only roughly 5% of what it can do. With keyboard maestro I don't see much point in writing one's own native automation apps. The APIs it exposes are just as powerful as what you could write yourself and a heck of a lot easier to use.