NSApplescript iTunes info is "forgotten"

Discussion in 'Mac Programming' started by adfriedm, Dec 28, 2011.

  1. adfriedm, Dec 28, 2011
    Last edited by a moderator: Dec 29, 2011

    macrumors newbie

    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
  2. Moderator emeritus


    You need to retain playerState.

Share This Page