如何在可可中获取applescript的变量值?

时间:2010-01-11 06:55:38

标签: cocoa macos applescript

    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init] ;

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

 source=@"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等的价值?'

提前致谢

1 个答案:

答案 0 :(得分:1)

Applescript返回最后执行的语句的值。在这种情况下,那是trating。在最后包含所有值(例如,列表)的语句。