This library sits on top of the macOS Accessibility API, making it easy to react when the user changes the active application, or when the window the user is focused on changes its title. It also includes some basic utilities for working with browsers.
The Swift Package Manager allows for developers to easily integrate packages into their Xcode projects and packages; and is also fully integrated into the swift compiler.
- File > Swift Packages > Add Package Dependency
- Add https://github.com/m1guelpf/WatchEye.git
- Select "Branch" with "main"
Once you have your Swift package set up, add the Git link within the dependencies value of your Package.swift file.
dependencies: [
.package(url: "https://github.com/m1guelpf/WatchEye.git", .branch("main"))
]
The easiest way to get started is to define a delegate and start reacting to events:
import AppKit
import WatchEye
import Foundation
class ExampleWatchEyeDelegate {
let watchEye: WatchEye
init() {
watchEye = WatchEye()
watchEye.delegate = self
}
}
extension ExampleWatchEyeDelegate: WatchEyeDelegate {
func watchEyeDidReceiveAccessibilityPermissions(_: WatchEye) {
print("Accessibility permissions granted!")
}
func watchEye(_: WatchEye, didFocusApplication app: NSRunningApplication) {
print("\(app.bundleIdentifier!) is now in focus")
}
func watchEye(_: WatchEye, didChangeTitleOf app: NSRunningApplication, newTitle title: String) {
if app.browser?.isIncognito(windowTitle: title) == true { return }
print("Title of \(app.bundleIdentifier!) changed to \(title)")
if let url = app.browser?.getURL() {
print("URL of \(app.bundleIdentifier!) is now \(url)")
}
}
}
This project is licensed under the MIT License - see the LICENSE file for details.