- if ([networkController isConnectedToServer]) {
- [statusItem setMenu:[menuController menu]];
- }
-
- if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
- ITDebugLog(@"The song changed.");
- timerUpdating = YES;
+ NSString *identifier = [[self currentRemote] playerStateUniqueIdentifier];
+ if (identifier == nil) {
+ if ([statusItem isEnabled]) {
+ [statusItem setToolTip:@"iTunes not responding."];
+ [[ITHotKeyCenter sharedCenter] setEnabled:NO];
+ }
+ [statusItem setEnabled:NO];
+ return;
+ } else if (![statusItem isEnabled]) {
+ [statusItem setEnabled:YES];
+ [statusItem setToolTip:_toolTip];
+ [[ITHotKeyCenter sharedCenter] setEnabled:YES];
+ return;
+ }
+
+ if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
+ ITDebugLog(@"The song changed. '%@'", _latestSongIdentifier);
+ if ([df boolForKey:@"runScripts"]) {
+ NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
+ NSEnumerator *scriptsEnum = [scripts objectEnumerator];
+ NSString *nextScript;
+ ITDebugLog(@"Running AppleScripts for song change.");
+ while ( (nextScript = [scriptsEnum nextObject]) ) {
+ NSDictionary *error;
+ NSAppleScript *currentScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"] stringByAppendingPathComponent:nextScript]] error:&error];
+ ITDebugLog(@"Running script: %@", nextScript);
+ if (!currentScript || ![currentScript executeAndReturnError:nil]) {
+ ITDebugLog(@"Error running script %@.", nextScript);
+ }
+ [currentScript release];
+ }
+ }