Hello
I renamed several variables to make your script more understandable.
When it IS a string (the name of a playlist) I use : somethingName
When it IS a list (a playlist) I use : somethingList
With these changes, I’m quite sure that you will understand better what is at work.
global playlistUpNextName
--Get Current Calendar Event via iCalBuddy hasseg.org/icalBuddy
set PlaylistTVShowName to first item of my text_to_list((do shell script "/usr/local/bin/icalbuddy -eed -nc -b \"\" eventsNow"), return) as text # Here, it is a string, no need to coerce it later
# Moved here and renamed to make clear that they are names (string) not playlist (list)
# As they are strings they aren't iTunes objects
set playlistMergedName to "Now Playing"
set PlaylistInterstitialsName to "[ID-D]" -- Intersitials for the [D]aytime broadcast.
set playlistUpNextName to "[some filler playlist TBD]"
tell application "iTunes"
--Shuffle based on "CK's Evenly-shuffled Playlists v0.6" by Charles Kelly http://www.manythings.org/mac/
if (playlist playlistMergedName) is {} then
set playlistMergedList to make new user playlist with properties {name:playlistMergedName} -- if no playlist, make it
else
set playlistMergedList to user playlist playlistMergedName -- if playlist, clean it out
--repeat # My understanding is that this instruction (and its end one) is useless
set tr to get tracks of playlistMergedList
--if tr is {} then exit repeat # Thanks to Nigel who pointed that it must be disabled!
repeat with t in tr
delete t
end repeat
--end repeat
end if
set x to count tracks of playlist PlaylistTVShowName -- length based on requested TV Show
set MergedTracks to {}
repeat with i from 1 to x
set theTrack to some track of playlist PlaylistInterstitialsName
set theTrackID to database ID of theTrack
set enabled of (duplicate theTrack to playlistMergedList) to true
set end of MergedTracks to theTrackID # do the same thing but I think that it's more clear
set theTrack to track i of playlist PlaylistTVShowName
set theTrackID to database ID of theTrack
set enabled of (duplicate theTrack to playlistMergedList) to true
set end of MergedTracks to theTrackID # do the same thing but I think that it's more clear
end repeat
--play playlist "Now Playing" -- use of playlistMerged gets "descriptor type mismatch" / current syntax results in "iTunes got an error: Parameter error." I DON'T KNOW WHAT TO BELIEVE ANYMORE.
play playlist playlistMergedName
set full screen to true
end tell
--wait for playlist to finish
on idle
tell application "iTunes"
try
if player state is not stopped then return 5
on error
return 5
end try
play playlist playlistUpNextName # defined as a global value
end tell
return 5
end idle
on text_to_list(txt, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
set AppleScript's text item delimiters to saveD
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
return theList
end text_to_list
Yvan KOENIG running Sierra 10.12.1 in French (VALLAURIS, France) samedi 10 décembre 2016 17:23:32