You can get the active app (the one whose menu bar is on screen) using NSRunningApplication. Get the list of all running apps and search for the one whose
activeproperty is true. You can also use KVO to be notified of changes.
If you’re looking for information inside the active app, things get trickier. Specifically:
There’s no general solution to this; you’ll need code that specific to the app you’re targeting.
Many of the techniques are restricted in some way. For example, one common approach is to use the accessibility API to look at UI elements within the app (starting with
AXUIElementCreateApplication), but that API requires that the user approve your app as an accessibility app (in System Preferences > Security & Privacy > Privacy > Accessibility).
Share and Enjoy
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"