문제

How do I get the returned value from an NSAppleScript. I am using apple script to get the song title in iTunes and take that value and set NSMenuItem's title.

My code: .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];

My code: .H

IBOutlet NSMenuItem *songName;
도움이 되었습니까?

해결책

You get a NSAppleEventDescriptor when you execute a NSAppleScript (not a NSString.

NSAppleEventDescriptor *theResult = [script executeAndReturnError:nil];
//set menu item title
[songName setTitle:[theResult stringValue]];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top