2014-05-17 10 views
2

QuickTime 플레이어가 일시 중지되었거나 Cocoa에서 재생 중인지 확인하려고합니다. 나는 스크립트 디버거와 애플 스크립트 편집기에서 다음과 같은 작은 애플 스크립트를 사용하고 예상대로 true 또는 false 반환- [NSAppleScript executeAndReturnError :] AppleScript 편집기에서 작동하는 스크립트에서 오류가 발생합니다.

tell application "QuickTime Player" to tell document 1 to return playing 

그러나, 코코아 응용 프로그램에서 다음과 같은 코드가 작동하지 않습니다 :

NSString *source = @"tell application \"QuickTime Player\" to tell document 1 to return playing"; 
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source]; 
NSDictionary *dict = nil; 
NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&dict]; 

위의 코드를 단계별 후 내 디버그 콘솔은 다음과 같습니다

debug console state

관련성이있는 경우 마지막 디버거 단계에 약 4 초가 걸리며 실행하려면 descriptor에 값을 할당하는 단계가 필요합니다.

은 내가 @autorelease 블록 내에서 바로 위에있는 간단한 명령 줄 도구 응용 프로그램을 구축하고, 그것을 작동합니다 : (QuickTime 플레이어가 실행 중일 때)

int main(int argc, const char * argv[]) 
{ 

    @autoreleasepool { 
     NSString *source = @"tell application \"QuickTime Player\" to tell document 1 to get playing"; 
     NSAppleScript *script = [[NSAppleScript alloc] initWithSource:source]; 
     NSDictionary *dict = nil; 
     NSAppleEventDescriptor *descriptor = [script executeAndReturnError:&dict]; 

     NSLog(@"%@", descriptor); 
     NSLog(@"%@", dict); 
    } 
    return 0; 
} 

그것은 출력의이다 :

2014-05-17 11:48:07.255 Sandbox[52872:303] <NSAppleEventDescriptor: 'true'("true")> 
2014-05-17 11:48:07.256 Sandbox[52872:303] (null) 
Program ended with exit code: 0 

디버거에서 샌드 박스 코드를 실행하면 descriptor 할당이 1 초 이내에 실행됩니다. 그래서이 일을 방지하는 응용 프로그램 프로젝트에서 다를 수 있습니까?

답변

2

나는 다른 것들에서 일하는 동안 내 마음이 배경에서 작동하는 동안 그 바보 같은 실수 중 하나였습니다.

샌드 박스. 앱이 샌드 박스 처리되고 권한으로 인해 iTunes Apple Events에 액세스 할 수 있지만 QuickTime Player 권한을 추가하지 않았습니다. 내가 만든 테스트 응용 프로그램은 샌드 박스가 아니기 때문에 정상적으로 작동했습니다.