Re: Detecting window title changes and kAXTitleChangeNotification
Re: Detecting window title changes and kAXTitleChangeNotification
- Subject: Re: Detecting window title changes and kAXTitleChangeNotification
- From: Paul Godavari <email@hidden>
- Date: Tue, 27 Jul 2010 19:01:14 -0700
Hi Bill, thanks for the reply.
I took a look at UI Browser and it does indeed notice window title changes on all the applications I tested. However, I'm still unable to get those notifications in my own application. I created a very simple Cocoa application to demonstrate the problem, listed below. From this app, I receive create, move and destroy notifications, but not the title changes. In my testing the app, I do not get any errors from any of the API calls.
Do you see any issues with my notification registrations?
@implementation AccessibilityAppDelegate
// Accessibility notification callback.
void AXCallback(AXObserverRef observer, AXUIElementRef element,
CFStringRef notificationName, void* contextData)
{
NSLog(@"Notification: %@", (NSString*) notificationName);
}
// Register to receive notifications for the process 'pid'.
- (void) registerProcess:(int)pid withName:(NSString*)name
{
NSLog(@"Registering application %@", name);
AXUIElementRef process = AXUIElementCreateApplication(pid);
AXObserverRef observer;
AXObserverCreate(pid, AXCallback, &observer);
AXObserverAddNotification(observer, process, kAXWindowCreatedNotification, self);
AXObserverAddNotification(observer, process, kAXUIElementDestroyedNotification, self);
AXObserverAddNotification(observer, process, kAXWindowMovedNotification, self);
AXObserverAddNotification(observer, process, kAXTitleChangedNotification, self);
CFRunLoopAddSource(CFRunLoopGetCurrent(),
AXObserverGetRunLoopSource(observer),
kCFRunLoopDefaultMode);
}
// Register for notifications on all running processes.
- (void) applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSArray* launchedApps = [[NSWorkspace sharedWorkspace] launchedApplications];
for (NSDictionary* dictionary in launchedApps) {
NSString* name = [dictionary objectForKey:@"NSApplicationName"];
int pid = [[dictionary objectForKey:@"NSApplicationProcessIdentifier"] intValue];
[self registerProcess:pid withName:name];
}
}
@end
Regards,
Paul
On Tue, Jul 27, 2010 at 3:20 PM, Bill Cheeseman
<email@hidden> wrote:
On Jul 27, 2010, at 5:44 PM, Paul Godavari wrote:
I have been able to detect window create, move and destroy operations, but not title change notifications. I've been trying to detect title changes by registering an AXObserver callback on the AXUIElementRef representing the window using the kAXTitleChangeNotification, but no notifications ever arrive for the observed windows.
That's the right way to do it, and it works for me. I run my UI Browser application and use its Notifications drawer to register a title changed notification on an Untitled TextEdit window. Then I save the TextEdit document to a name, and as soon as it's saved, the UI Browser Notifications Log window shows the title changed notification. <
http://pfiddlesoft.com/uibrowser/>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden