-- BP Jan 2014 Feb 2021
-- SetPlayCountofTrackorPlaylistSelectedTracks
(*
Will modify playcount of single track, all selected tracks, or all tracks in a playlist.
Beware, the single track version, as it looks for that trackname in the entire music library, and
changes the first instance it finds. -That may not be the one you want.
DoSelectedOnly value takes precedence over DoEntirePlaylist, which takes precedence over DoSingleTrack
*)
-- User settable variables
set DoSelectedOnly to 1 -- 0 is no, 1 is yes
set DoEntirePlaylist to 0 -- 0 is no, 1 is yes
set DoSingleTrack to 0 -- 0 is no, 1 is yes
set TheName to "" -- Either the track name or the name of the playlist
set ThePlayCount to 11 -- can also use the script to set enabled to true or false
-- End of user settable variables
---------------------------------
tell application "Music"
activate
if DoSelectedOnly is greater than 0 then
if selection is not {} then
set tracklst to selection
set trackcount to number of items in tracklst
repeat with n from 1 to trackcount
set played count of (item n of tracklst) to ThePlayCount
--set enabled of (item n of tracklst) to false
end repeat
end if
else if DoEntirePlaylist is greater than 0 then
-- Do a whole playlist:
set tracklst to every track of playlist TheName
-- The last member of a "never played" smart list WILL be skipped
-- I can set it by name, but not via reffing it's place in a playlist that's about to be emptied. Probably Apple kludgery.
set trackcount to number of items in tracklst
repeat with n from 1 to trackcount
set played count of (item n of tracklst) to ThePlayCount
end repeat
else if DoSingleTrack is greater than 0 then
set played count of track named TheName to ThePlayCount
end if
end tell