View Full Version : NSApplescript iTunes info is "forgotten"

Dec 28, 2011, 06:07 PM
I'm quite new to objective-C and come from Java and C++, so I am not too comfortable with the NSAutoreleasePool yet (if this is related to that). The error I'm getting is EXC_BAD_ACCESS. Anyway:


#import <Cocoa/Cocoa.h>
@interface myController : NSObject {
IBOutlet NSButton *PlayPauseLabel;

// Script stuff
NSAppleScript* getPlayerStateScript;

NSString* playerState;
- (IBAction)backPress:(id)sender;
- (IBAction)forwPress:(id)sender;
- (IBAction)plPaPress:(id)sender;


#import "myController.h"

@implementation myController

- (void)awakeFromNib {
getPlayerStateScript = [[NSAppleScript alloc] initWithSource:[NSString stringWithFormat:@"tell application\"iTunes\"\n return player state as string\n end tell"]];
playerState = [[getPlayerStateScript executeAndReturnError:nil] stringValue];

NSLog (@"%@", playerState); // This works

- (IBAction)backPress:(id)sender {
NSLog (@"%@", playerState); // This doesn't work

Any help would be greatly appreciated

Dec 28, 2011, 08:14 PM
You need to retain playerState.