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];
위의 코드를 단계별 후 내 디버그 콘솔은 다음과 같습니다
관련성이있는 경우 마지막 디버거 단계에 약 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 초 이내에 실행됩니다. 그래서이 일을 방지하는 응용 프로그램 프로젝트에서 다를 수 있습니까?