Implemented running scripts on song change.
authorKent Sutherland <ksuther@ithinksw.com>
Fri, 30 Jan 2004 21:38:53 +0000 (21:38 +0000)
committerKent Sutherland <ksuther@ithinksw.com>
Fri, 30 Jan 2004 21:38:53 +0000 (21:38 +0000)
MainController.m
MenuController.m
StatusWindowController.m
iTunesRemote.m
libValidate.a

index 307800f..f9e23ed 100755 (executable)
@@ -305,6 +305,21 @@ static MainController *sharedController;
     
     if ( [self songChanged] && (timerUpdating != YES) && (playerRunningState == ITMTRemotePlayerRunning) ) {
         ITDebugLog(@"The song changed.");
+        
+        if ([df boolForKey:@"runScripts"] && [[self currentRemote] currentSongTitle]) {
+            NSArray *scripts = [[NSFileManager defaultManager] directoryContentsAtPath:[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"]];
+            NSEnumerator *scriptsEnum = [scripts objectEnumerator];
+            NSString *nextScript;
+            while ( (nextScript = [scriptsEnum nextObject]) ) {
+                NSDictionary *error;
+                NSAppleScript *currentScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Library/Application Support/MenuTunes/Scripts"] stringByAppendingPathComponent:nextScript]] error:&error];
+                if (!currentScript || ![currentScript executeAndReturnError:nil]) {
+                    ITDebugLog(@"Error running script %@.", nextScript);
+                }
+                [currentScript release];
+            }
+        }
+        
         timerUpdating = YES;
         
         NS_DURING
index b7f8f85..c2970f6 100755 (executable)
@@ -21,7 +21,7 @@
 - (NSMenu *)playlistsMenu;
 - (NSMenu *)eqMenu;
 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
-        onItem:(NSMenuItem *)item;
+        onItem:(id <NSMenuItem>)item;
 //- (BOOL)iPodAtPathAutomaticallyUpdates:(NSString *)name;
 @end
 
@@ -42,7 +42,7 @@
     NSArray *menuArray = [defaults arrayForKey:@"menu"];
     NSEnumerator *enumerator = [menuArray objectEnumerator];
     NSString *nextObject;
-    NSMenuItem *tempItem;
+    id <NSMenuItem> tempItem;
     NSEnumerator *itemEnum;
     ITHotKey *hotKey;
     NSArray *hotKeys = [[ITHotKeyCenter sharedCenter] allHotKeys];
 - (NSMenu *)menuForNoPlayer
 {
     NSMenu *menu = [[NSMenu alloc] initWithTitle:@""];
-    NSMenuItem *tempItem;
+    id <NSMenuItem> tempItem;
     ITDebugLog(@"Creating menu for when player isn't running.");
     NS_DURING
         ITDebugLog(@"Add \"Open %@\" menu item.", [[[MainController sharedController] currentRemote] playerSimpleName]);
                     NS_HANDLER
                         [[MainController sharedController] networkError:localException];
                     NS_ENDHANDLER
-                    NSMenuItem *songItem;
+                    id <NSMenuItem> songItem;
                     ITDebugLog(@"Adding song: %@", curSong);
                     songItem = [upcomingSongsMenu addItemWithTitle:curSong action:@selector(performUpcomingSongsMenuAction:) keyEquivalent:@""];
                     [songItem setTag:i];
 {
     NSMenu *playlistsMenu = [[NSMenu alloc] initWithTitle:@""];
     NSArray *playlists;
-    NSMenuItem *tempItem;
+    id <NSMenuItem> tempItem;
     ITMTRemotePlayerSource source = [[[MainController sharedController] currentRemote] currentSource];
     int i;
     NS_DURING
 {
     NSMenu *eqMenu = [[NSMenu alloc] initWithTitle:@""];
     NSArray *eqPresets;
-    NSMenuItem *tempItem;
+    id <NSMenuItem> tempItem;
     int i;
     
     NS_DURING
 }
 
 - (void)setKeyEquivalentForCode:(short)code andModifiers:(long)modifiers
-        onItem:(NSMenuItem *)item
+        onItem:(id <NSMenuItem>)item
 {
     unichar charcode = 'a';
     int i;
index 3e7522e..3108cd9 100755 (executable)
@@ -115,7 +115,6 @@ static StatusWindowController *sharedController;
     
     if ( art != nil ) {
         image = art;
-        NSSize size = [image size];
         [image setScalesWhenResized:YES];
         [image setSize:NSMakeSize(110, 110)];
         /*if (size.width > 110 && size.width > size.height) {
index 3c1ce75..7a0c9cb 100755 (executable)
 {
     NSAppleScript *script;
     NSAppleEventDescriptor *moof;
-    NSData  *data;
+    NSData *data;
+    ITDebugLog(@"Getting current song album art.");
     script = [[NSAppleScript alloc] initWithSource:@"tell application \"iTunes\"\nget data of artwork 1 of current track\nend tell"];
     moof = [script executeAndReturnError:nil];
     data = [moof data];
+    ITDebugLog(@"Getting current song album art done.");
     if (data) {
         return [[[NSImage alloc] initWithData:data] autorelease];
     } else {
index 576d85e..a3d44e3 100755 (executable)
Binary files a/libValidate.a and b/libValidate.a differ