I have put together a script that will process song information from a text file with comma seperated values, and add them to a playlist. It will also write the values it could not locate to a text file. This works well, but I would like to implement additional functionality. I have added the ability to select a song when the search results are more than one. However, it doesn't matter what I select from the list. It always adds the song at the very beginning of the selection regardless of what is chosen. Any help would be greatly appreciated.
Code:
set myPrefsFile to (choose file with prompt "Select a file to read:")
set notfound to ((path to desktop folder) as string) & "notfound.txt"
open for access notfound with write permission
open for access myPrefsFile
set AppleScript's text item delimiters to {","}
set prefsContents to read myPrefsFile using delimiter {","}
close access myPrefsFile
set x to 0
set theplaylist to "Temp"
tell application "iTunes"
make new user playlist with properties {name:"Temp-1"}
end tell
repeat number of items in prefsContents times
set x to x + 1
set track_name to item x of prefsContents
tell application "iTunes"
get view of front window
tell library playlist 1
set search_results to (search for track_name)
copy search_results to theplaylist
end tell
if search_results's length > 1 then
set trackNames to {}
set trackartist to {}
repeat with thisTrack in search_results
try
set end of trackNames to (artist of thisTrack & " - " & name of thisTrack as string)
on error
set end of trackNames to "<track name missing>"
end try
end repeat
set myresult to (choose from list trackNames)
repeat with myresult in search_results
duplicate myresult to playlist "Temp-1"
if 1 = 1 then exit repeat
end repeat
else
repeat with myresult in search_results
duplicate myresult to playlist "Temp-1"
if 1 = 1 then exit repeat
end repeat
end if
end tell
if search_results = {} then write track_name to file notfound
end repeat
close access file notfound
Last edited by a moderator: