Hi, I have 3 tracks in iTunes and run this procedure:
-(IBAction)reloadButtonClick:(id)sender;
{
NSAppleScript *script ;
NSString *source ;
NSString *result;
NSDictionary *errorDic ;
NSAppleEventDescriptor *ed;
int total;
source= @"tell application \"iTunes\" to get count of tracks of playlist 1";
script = [[NSAppleScript alloc] initWithSource:source];
ed = [script executeAndReturnError:&errorDic];
if (ed == nil)
{
NSAlert *alert = [[NSAlert alloc]init];
[alert setMessageText:@"Error Occurred"];
[alert runModal];
[alert release];
}
result = [ed stringValue];
total = [result intValue];
NSAlert *alert = [[NSAlert alloc]init];
[alert setMessageText:[NSString stringWithFormat:@"%d",total]];
[alert runModal];
[alert release];
}
It always returns 0 and error is not occurred. But, if I execute the script inside Script Editor, it returns 3.
Anyone know what is wrong ? Is AppleScript inside cocoa unstable ?
Thanks.
PS: my iTunes version is 8.0.2 (20)