2012-07-13 58 views
-2

如何获取NSAppleScript的返回值。 我正在使用苹果脚本在iTunes中获取歌曲标题并获取该值并设置NSMenuItem的标题。NSAppleScript返回值

我的代码:.M

//run applescript 
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"tell application  \"iTunes\" to set song to name of current track"]; 
[script executeAndReturnError:nil]; 
//set menu item title 
[songName setTitle:script]; 

我的代码:.H

IBOutlet NSMenuItem *songName; 
+0

。这不是一个完整的问题,当你运行代码时会发生什么?你试过什么吗? – Dustin 2012-07-13 16:30:42

+0

@DustinRowland当我运行代码_is_我尝试过的代码时没有任何反应。 – atomikpanda 2012-07-13 18:32:31

回答

2

你得到一个NSAppleEventDescriptor当你执行一个NSAppleScript(不是的NSString

NSAppleEventDescriptor *theResult = [script executeAndReturnError:nil]; 
//set menu item title 
[songName setTitle:[theResult stringValue]];