我试图建立一个程序,输出我几乎所有选定的应用程序。但是由于某种原因,我得到了AXError:-25204。根据参考资料,此错误意味着我试图表示的应用程序正处于繁忙或无响应状态。我不明白为什么..。
我在本教程的指导下工作:http://cocoatutorial.grapewave.com/2010/01/retrieving-the-window-that-has-focus/
#import <Foundation/Foundation.h>
#import <AppKit/NSAccessibility.h>
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
if(!AXAPIEnabled()){
NSLog(@"AXAPI not Enabled");
return 0;
}
AXUIElementRef _systemWideElement;
AXUIElementRef _focusedApp;
CFTypeRef _focusedWindow;
CFTypeRef _position;
CFTypeRef _size;
AXError e;
//Get the window that has the focus
//Get the app that has the focus
_systemWideElement = AXUIElementCreateSystemWide();
NSLog(@"%d",_systemWideElement);
e=AXUIElementCopyAttributeValue(_systemWideElement,
(CFStringRef)kAXFocusedApplicationAttribute,
(CFTypeRef*)&_focusedApp);
NSLog(@"%d,%d",kAXErrorSuccess,e);
e=AXUIElementCopyAttributeValue((AXUIElementRef)_focusedApp,(CFStringRef)NSAccessibilityFocusedWindowAttribute,(CFTypeRef*)&_focusedWindow);
if( e == kAXErrorSuccess) {
NSLog(@"App ausgewaehlt");
if(CFGetTypeID(_focusedWindow) == AXUIElementGetTypeID()) {
//Get the Window's Current Position
if(AXUIElementCopyAttributeValue((AXUIElementRef)_focusedWindow,
(CFStringRef)NSAccessibilityPositionAttribute,
(CFTypeRef*)&_position) != kAXErrorSuccess) {
NSLog(@"Can't Retrieve Window Position");
}
//Get the Window's Current Size
if(AXUIElementCopyAttributeValue((AXUIElementRef)_focusedWindow,
(CFStringRef)NSAccessibilitySizeAttribute,
(CFTypeRef*)&_size) != kAXErrorSuccess) {
NSLog(@"Can't Retrieve Window Size");
}
}
//NSLog(@"%@",_size);
}else {
NSLog(@"%d",e);
}
[pool drain];
return 0;}
有人有主意了吗?
发布于 2013-07-25 01:14:00
我相信您应该使用kAXFocusedWindowAttribute,也可能是kAXSizeAttribute,而不是NSAccessibility应用程序接口,它们都是有文档记录的here。根据我的经验,您不希望混合使用这两个API,而是希望使用APIs来访问其他应用程序的元素。
https://stackoverflow.com/questions/17126140
复制相似问题