Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Searching for a similar song in iTunes

Hi,


I'd like to get all the similar songs of a selected track with similar name and same artist.


Here is my script :

tell application "iTunes"
  set theSelection to selection
  set t to (item 1 of theSelection)
  set artist_name to artist of t
  set track_name to name of t
  set results to (file tracks whose artist is artist_name and name contains track_name)
  return results
end tell


Everything is ok except I get the selected song in the results and I want to exclude it.


How to do that ?


Thx.

Posted on May 9, 2015 2:16 PM

Reply
5 replies

May 16, 2015 10:06 AM in response to Combo

Hi,


Combo wrote:

One more thing, is it possible to show the results in a list to select one item ?


Thx.


Yes, it's possible.


tell application "iTunes"
     set t to item 1 of (get selection)
     set {artist:a_name, name:t_name, database ID:dbID} to t
     set tTracks to a reference to (file tracks whose artist is a_name and name contains t_name and database ID is not dbID)
     if (count tTracks) = 0 then return {} -- no match
     set namesList to name of tTracks
     set tResult to choose from list namesList
     if tResult is false then return {} -- user canceled
     set thisName to item 1 of tResult
     repeat with i from 1 to tc
          if item i of namesList = thisName then return item i of tTracks
     end repeat
end tell

May 17, 2015 11:01 AM in response to Combo

Hi,


Combo wrote:

About the result selected in the list, is there a way to get the index selected to match it with the tTracks instead of getting a string ?


It's not possible without adding a number before each name in the list :



tell application "iTunes"
     set t to item 1 of (get selection)
     set {artist:a_name, name:t_name, database ID:dbID} to t
     set tTracks to (file tracks whose artist is a_name and name contains t_name and database ID is not dbID)
     set tc to count tTracks
     if tc = 0 then return {} -- no match 
     set namesList to {}
     repeat with i from 1 to tc
          set end of namesList to "" & i & " - " & name of item i of tTracks
     end repeat
     set tResult to choose from list namesList
     if tResult is false then return {} -- user canceled 
     set tIndex to word 1 of (item 1 of tResult)
     return item tIndex of tTracks
end tell

Searching for a similar song in iTunes

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.