Re: What Does kAXFocusedApplicationAttribute return when called for the sysWide accessiblity object?
Re: What Does kAXFocusedApplicationAttribute return when called for the sysWide accessiblity object?
- Subject: Re: What Does kAXFocusedApplicationAttribute return when called for the sysWide accessiblity object?
- From: aaron smith <email@hidden>
- Date: Tue, 4 Aug 2009 00:39:57 -0700
I think I got it figured out. I was just calling those methods to
quickly. If I waited a few seconds then it was fine.. I put in a
button to trigger the methods, instead of on wake from nib..
On Mon, Aug 3, 2009 at 10:57 PM, aaron
smith<email@hidden> wrote:
> Sorry, here's a pastebin of the same code. it's just more readable..
>
> http://pastebin.com/m2f043071
>
>
>
> On Mon, Aug 3, 2009 at 10:53 PM, aaron
> smith<email@hidden> wrote:
>> Hey All, quick question. what is returned when getting the
>> kAXFocusedApplicationAttribute attribute, from the syswide
>> accessibility object?
>>
>> Ultimately what I'm trying to do is get the front focused window. I've
>> tried a couple things. Here's a breakdown of what i'm experiencing:
>>
>> -If I get an application directly with AXUIElementCreateApplication(),
>> then get the NSAccessibilityFocusedWindowAttribute, it works fine.
>> -If I get the focused application from the syswide access object, then
>> try to get the NSAccessibilityFocusedWindowAttribute, it tells me that
>> the API is disabled?
>>
>> Here's some code to demonstrate what I've got going, and the output of
>> this code follows. Any help is greatly appreciated. Thanks again.
>>
>> - (void) awakeFromNib {
>> [self testApp:TRUE];
>> [self testApp:FALSE];
>> }
>>
>> - (void) testApp:(Boolean)usepid {
>> CFTypeRef focusedWindow = NULL;
>> CFTypeRef position = NULL;
>> AXUIElementRef appref;
>> if(usepid) {
>> printf("USING PID\n");
>> pid_t xcode = 330;
>> appref = AXUIElementCreateApplication(xcode);
>> }else {
>> printf("\n\nUSING SYS\n");
>> AXUIElementRef sys = AXUIElementCreateSystemWide();
>> [self printElementRefAttributes:sys];
>> AXUIElementCopyAttributeValue(sys,(CFStringRef)kAXFocusedApplicationAttribute,(CFTypeRef
>> *)&appref);
>> }
>> printf("PRINTING ATTRIBUTES FOR appref\n");
>> [self printElementRefAttributes:appref];
>> if(AXUIElementCopyAttributeValue((AXUIElementRef)appref,(CFStringRef)NSAccessibilityFocusedWindowAttribute,(CFTypeRef*)&focusedWindow)
>> == kAXErrorSuccess) {
>> if(CFGetTypeID(focusedWindow) == AXUIElementGetTypeID()) {
>> printf("PRINTING ATTRIUBUTES FOR FOCUSED WINDOW\n");
>> [self printElementRefAttributes:(AXUIElementRef)focusedWindow];
>> if(AXUIElementCopyAttributeValue((AXUIElementRef)focusedWindow,(CFStringRef)NSAccessibilityPositionAttribute,(CFTypeRef
>> *)&position) == kAXErrorSuccess) {
>> if(AXValueGetType(position) == kAXValueCGPointType) {
>> printf("ITS A POINT\n");
>> NSPoint thePoint;
>> AXValueGetValue((AXValueRef)position,kAXValueCGPointType,&thePoint);
>> printf("%g\n",thePoint.x);
>> }
>> }
>> }
>> }
>> }
>>
>> - (void) printElementRefAttributes:(AXUIElementRef)elementRef {
>> NSArray *attributes = NULL;
>> if(AXUIElementCopyAttributeNames(elementRef,(CFArrayRef
>> *)&attributes) == kAXErrorSuccess ) {
>> printf("--PRINTING ATTRIBUTE NAMES--\n");
>> NSEnumerator * enumer = [attributes objectEnumerator];
>> NSString *attributeName;
>> while(attributeName = [enumer nextObject])
>> printf("%s\n",[attributeName UTF8String]);
>> } else {
>> printf("cannot print attribute names
>> (%i)\n",AXUIElementCopyAttributeNames(elementRef,(CFArrayRef
>> *)&attributes));
>> }
>> }
>>
>> Please excuse some of the print statements. that's just to show this
>> example.. Here's the output when I run this:
>>
>> USING PID
>> PRINTING ATTRIBUTES FOR appref
>> --PRINTING ATTRIBUTE NAMES--
>> AXRole
>> AXRoleDescription
>> AXTitle
>> AXChildren
>> AXMenuBar
>> AXWindows
>> AXFrontmost
>> AXHidden
>> AXMainWindow
>> AXFocusedWindow
>> AXFocusedUIElement
>> AXEnhancedUserInterface
>> PRINTING ATTRIUBUTES FOR FOCUSED WINDOW
>> --PRINTING ATTRIBUTE NAMES--
>> AXRole
>> AXRoleDescription
>> AXSubrole
>> AXTitle
>> AXFocused
>> AXParent
>> AXChildren
>> AXPosition
>> AXSize
>> AXMain
>> AXMinimized
>> AXCloseButton
>> AXZoomButton
>> AXMinimizeButton
>> AXToolbarButton
>> AXProxy
>> AXTitleUIElement
>> AXGrowArea
>> AXDefaultButton
>> AXCancelButton
>> AXDocument
>> AXModal
>> ITS A POINT
>> 0
>>
>>
>> USING SYS
>> --PRINTING ATTRIBUTE NAMES--
>> AXRole
>> AXRoleDescription
>> AXFocusedUIElement
>> AXFocusedApplication
>> PRINTING ATTRIBUTES FOR appref
>> cannot print attribute names (-25211)
>>
>
_______________________________________________
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