2010-01-11 5 views
1
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init] ; 

NSAppleEventDescriptor *eventDescriptor; 
NSAppleScript *script ; 
NSString* source ; 
NSDictionary* errorDic ; 

[email protected]"tell application \"iTunes\" \n" 
@"set tname to name of track 1 of playlist 1 \n" 
@"set tartist to artist of track 1 of playlist 1 \n" 
@"set talbum to album of track 1 of playlist 1 \n" 
@"set ttime to time of track 1 of playlist 1 \n" 
@"set tbitrate to bit rate of track 1 of playlist 1 \n" 
@"set tsize to size of track 1 of playlist 1 \n" 
@"set trating to rating of track 1 of playlist 1 \n" 
@"end tell"; 

script = [[NSAppleScript alloc] initWithSource:source]; 
eventDescriptor = [script executeAndReturnError:&errorDic]; 
NSString* frontUrl = [eventDescriptor stringValue]; 
NSLog(frontUrl); 

/*NSAlert *alert = [[NSAlert alloc]init]; 
[alert setMessageText:frontUrl]; 
[alert runModal]; 
[alert release];*/ 

[pool release] ; 

NSlog는 트랙 등급 만 표시합니다. tname, tartist, talbum 등의 가치를 얻는 방법? '코코아에서 applescript의 변수 값을 얻는 방법은 무엇입니까?

답변

1

AppleScript를 실행 마지막 문장의 값을 반환 사전에

감사합니다. 이 경우는 trating입니다. 모든 값 (예 : 목록)이 들어있는 문장을 끝에 넣으십시오.

+0

내가 1 \t 말할 mydata을 끝을 얻을 재생 목록의 트랙 1의 {영구적 인 ID, 이름, 아티스트, 앨범}를 얻을 수 TELL 응용 프로그램의 "iTunes" \t 설정 mydata을 변경하려고 하지만, 결과는 null – Irwan

+1

'{tname, tartist, talbum, ttime, tbitrate, tsize, trating}'만 반환하면됩니다. 일단 작동하면 목록 대신 레코드를 반환하고 처리하여 AppleScript 코드와 Cocoa 코드간에 동의하는 인덱스에 의존하지 않도록 할 수 있습니다. –

+0

감사합니다 피터! 효과가있다. – Irwan

관련 문제