I've found Apple Music can get into an inconsistent state. This corrects that state
--
-- This script looks for an inconsistent state and fixes it
-- Select a set of tracks in Apple Music. Then this script iterates over the selected tracks
-- If the play count is 0, but the last played date exists, then set the play count to 1
-- I suppose you could also do the opposite: if the play count is not zero, but
-- last played date is missing, you could set it.
-- I'll leave that as an exercise to the reader.
--
-- Author Ike Nassi (nassi@nassi.com)
-- Date 2022-12-26
--
tell application "Music"
set tunesList to selection
if length of tunesList is 0 then
display dialog "List is empty"
return
end if
set changesMade to false
repeat with aTune in tunesList
-- display dialog "Name that tune: " & name of aTune
if (played count of aTune is 0) then
-- display dialog "Played Date of " & name of aTune & " is " & (played date of aTune)
if (played date of aTune) is not missing value then
display dialog "Played Date of " & name of aTune & "is empty, so set to 1"
set played count of aTune to 1
set changesMade to true
end if
end if
end repeat
if changesMade then
display dialog "Changes made"
else
display dialog "No changes necessary"
end if
end tell