You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For example, I want to monitor the size and position of the text box of the TextEdit window:
Open the TextEdit app.
Press Command + N to create a new text editing window.
Press Command + Shift + . to enlarge the text box.
The size of the text box is enlarged, but the change of the size and position of the text cannot be monitored through .moved and .resized.
my code is invalid:
varobserver:Observer!publicfunc applicationDidFinishLaunching(_ aNotification:Notification){
// let app = Application.allForBundleID("com.apple.finder").first!
letapp=Application.allForBundleID("com.apple.TextEdit").first!
do{trystartWatcher(app)}catchlet error{NSLog("Error: Could not watch app [\(app)]: \(error)")abort()}}func startWatcher(_ app:AXSwift.Application)throws{varupdated=false
observer = app.createObserver{(observer:Observer, element:UIElement, event:AXNotification, info:[String:AnyObject]?)invarelementDesc:String!iflet role =try? element.role()!, role ==.window {
elementDesc ="\(element)\"\(try!(element.attribute(.title)asString?)!)\""}else{
elementDesc ="\(element)"}print("\(event) on \(String(describing: elementDesc)); info: \(info ??[:])")
// Watch events on new windows
if event ==.windowCreated {do{try observer.addNotification(.uiElementDestroyed, forElement: element)try observer.addNotification(.moved, forElement: element)try observer.addNotification(.resized, forElement: element)try observer.addNotification(.created, forElement: element)}catchlet error{NSLog("Error: Could not watch [\(element)]: \(error)")}}if event ==.created || event ==.focusedUIElementChanged {do{try observer.addNotification(.moved, forElement: element)try observer.addNotification(.resized, forElement: element)}catchlet error{NSLog("Error: Could not watch [\(element)]: \(error)")}}
// Group simultaneous events together with --- lines
if !updated {
updated =true
// Set this code to run after the current run loop, which is dispatching all notifications.
DispatchQueue.main.async{print("---")
updated =false}}}try observer.addNotification(.windowCreated, forElement: app)try observer.addNotification(.mainWindowChanged, forElement: app)try observer.addNotification(.created, forElement: app)try observer.addNotification(.focusedUIElementChanged, forElement: app)}
The text was updated successfully, but these errors were encountered:
For example, I want to monitor the size and position of the text box of the TextEdit window:
my code is invalid:
The text was updated successfully, but these errors were encountered: