X-Git-Url: http://git.ithinksw.org/MenuTunes.git/blobdiff_plain/b5111a52983c34e3d63dd8547a1f259a7cb5edda..f75034b0016748a0727852ce6c94c22350bbc101:/iTunesRemote.m diff --git a/iTunesRemote.m b/iTunesRemote.m index b4479a9..35c9990 100755 --- a/iTunesRemote.m +++ b/iTunesRemote.m @@ -770,6 +770,44 @@ return YES; } +- (BOOL)makePlaylistWithTerm:(NSString *)term ofType:(int)type +{ + int i; + + //Get fixed indexing status + BOOL fixed = [ITSendAEWithString(@"'----':obj { form:'prop', want:type('prop'), seld:type('pFix'), from:'null'() }", 'core', 'getd', &savedPSN) booleanValue]; + + //Enabled fixed indexing + ITSendAEWithString(@"data:long(1), '----':obj { form:'prop', want:type('prop'), seld:type('pFix'), from:'null'() }", 'core', 'setd', &savedPSN); + + //Search for the term + NSAppleEventDescriptor *searchResults = ITSendAEWithString([NSString stringWithFormat:@"pTrm:\"%@\", pAre:'%@', '----':obj { form:'indx', want:type('cPly'), seld:long(1), from:obj { form:'indx', want:type('cSrc'), seld:long(1), from:'null'() } }", term, ((type == 1) ? @"kSrR" : @"kSrL")], 'hook', 'Srch', &savedPSN); + + //If MenuTunes playlist exists + if ([ITSendAEWithString(@"'----':obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:'null'() }", 'core', 'doex', &savedPSN) booleanValue]) { + //Clear old MenuTunes playlist + int numSongs = [ITSendAEWithString(@"kocl:type('cTrk'), '----':obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:obj { form:'prop', want:type('prop'), seld:type('ctnr'), from:obj { form:'prop', want:type('prop'), seld:type('pPla'), from:'null'() } } }", 'core', 'cnte', &savedPSN) int32Value]; + for (i = 1; i <= numSongs; i++) { + ITSendAEWithString(@"'----':obj { form:'indx', want:type('cTrk'), seld:long(1), from:obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:'null'() } }", 'core', 'delo', &savedPSN); + } + } else { + //Create MenuTunes playlist + ITSendAEWithString(@"prdt:{ pnam:\"MenuTunes\" }, kocl:type('cPly'), &subj:()", 'core', 'crel', &savedPSN); + } + + //Duplicate search results to playlist + for (i = 1; i <= [searchResults numberOfItems]; i++) { + ITSendAEWithStringAndObject(@"insh:obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:'null'() }", [[searchResults descriptorAtIndex:i] aeDesc], 'core', 'clon', &savedPSN); + } + //Reset fixed indexing + ITSendAEWithString([NSString stringWithFormat:@"data:long(%i), '----':obj { form:'prop', want:type('prop'), seld:type('pFix'), from:'null'() }", fixed], 'core', 'setd', &savedPSN); + + //Play MenuTunes playlist + //ITSendAEWithString(@"'----':obj { form:'name', want:type('cPly'), seld:\"MenuTunes\", from:'null'() }", 'hook', 'Play', &savedPSN); + + return YES; +} + - (ProcessSerialNumber)iTunesPSN { /*NSArray *apps = [[NSWorkspace sharedWorkspace] launchedApplications];