When I call the AXUIElementGetAttributeValueCount function, I get the kAXErrorCannotComplete error. Please advise.
The following is the relevant code
ProcessSerialNumber psn = {
0,kNoProcess
};
Boolean findProcess = NO;
int ncount = 0;
do{
while (noErr == GetNextProcess(&psn)) {
CFStringRef name = NULL;
CopyProcessName(&psn, &name);
NSString *appName = [[NSString alloc]initWithFormat:@"%@",name];
if ([appName isEqualToString:@"mainApp"]) {
findProcess = YES;
break;
}
}
if (findProcess == YES) {
break;
}
}while (ncount++ < 3);
if (findProcess)
{
pid_t pid;
GetProcessPID(&psn, &pid);
NSLog(@"-%d-",pid);
AXUIElementRef element = AXUIElementCreateApplication(pid);
Boolean isTrusted = AXIsProcessTrustedWithOptions(CFDictionaryCreate(NULL, (const void*[]) { kAXTrustedCheckOptionPrompt }, (const void*[]){ kCFBooleanTrue }, 1, NULL, NULL));
if (isTrusted)
{
NSLog(@"the API Enabled");
CFIndex count = 0;
AXError sExx = AXUIElementGetAttributeValueCount(element, kAXWindowsAttribute, &count);
NSLog("%d",sExx); //the AXError is -25204 kAXErrorCannotComplete
}
}