Setting Play Count in Music app

Hi. I don’t have anything later than Mojave installed, but perhaps you could test this.

tell application "iTunes"
	tell (playlist "Enya"'s tracks whose kind contains "audio" and location is not missing value)
		set unplayed to 1
		tracks's played count
	end tell
end tell

The Doug’s Script isn’t script but Doug’s Application. Assuming it works as you say, try to save my script in post #6 as application. If it will ask for some permissions, grant them. If it will work in application form, then the bug is related to script form. You can then solve this bug granting the same permissions to your Script Editor. Or, you can’t.

Once I change “iTunes” to “Music,” I get an error on run: "Music got an error: Unknown object type.” The word “unplayed” is selected, so I assume that “unplayed” is an unknown object type in Music.

That didn’t help. However, I did manage to get it working, although without any error-checking or anything, as that’s beyond my current skill level:

tell application "Music"
	repeat with t in (get tracks of playlist "Play Count Util")
		set the played count of t to 0
	end repeat
	set shuffle enabled to false
	play playlist "Go Through"
end tell

I…don’t know what in your script isn’t working, but at least we now know that it’s possible.

Now this is difficult to establish, so you threw out the check for the track class and the check for the fact that the play count is already = 0. Apparently, you are indifferent to debugging the script line by line and familiarizing users with the thrown error. If at all this error has ever been thrown. Because everything worked for me already starting from post # 6. I will remember you as a user with whom it is better not to communicate anymore. To preserve nerve cells.

Read the posting guidelines again and try to control your urge to attack other posters. If you’re not getting anywhere with them, simply stop replying.

I am very, very, very confused.

I’ve established that this is possible. I’ve found the basic problem. I tried to put my change back into your script, but it didn’t work. So there’s something wrong here that I don’t know what it is. I don’t know how to debug line by line if I can’t get the original script to work at all. Should I just throw random lines from your script in and see if they fail? That seems like a futile task. I was hoping that the information I gave would shed light on the problem.

I think you’re expecting me to know AppleScript well, but if I did, I probably wouldn’t need to have posted this problem.

Hi. Debugging line by line is more or less how you have to explore otherwise inexplicable errors. Whether new or old to scripting, it’s essential that you have feedback, so you should view the event log; click on the far right icon on the Script Editor’s window’s bottom with ‘Events’ or ‘Replies’ selected in the bar above it. What is the result from this?

tell application "iTunes"
	tell playlist "Play Count Util"'s tracks 1 thru 5 to try --adjust arbitrary number as needed for representative sample 
		unplayed
	on error err
		{played count, kind, its class, location, err}
	end try
end tell

tell application “Music”
get unplayed of tracks 1 thru 5 of playlist “Play Count Util”
→ {false, false, false, false, false}
end tell
Result:
{false, false, false, false, false}

And this?

tell application "iTunes"
   tell playlist "Play Count Util"'s tracks 1 thru 5
		try
			set unplayed to 1
			return unplayed
		end try
		try
			set played count to 0
		on error
			beep 3
		end try
		{unplayed, played count}
	end tell
end tell

tell application “Music”
set unplayed of tracks 1 thru 5 of playlist “Play Count Util” to 1
→ {current application, current application, current application, current application, current application}
get unplayed of tracks 1 thru 5 of playlist “Play Count Util”
→ {true, true, true, true, true}
end tell
Result:
{true, true, true, true, true}

Those results demonstrate a change took place in the unplayed property; by definition, those tracks should have a zero play count, so you can extend this idea to attempt to change all the tracks in that playlist or continue to experiment with testing their played count, kind, class, and location properties to see if there’s some reason why some are settable but others are not.

I know this is an old thread, but just for the record I think the very first script will work if you amend this line:

if class of t is file track or class of t is URL track then

to this:

if class of t is file track or class of t is URL track or class of t is shared track then

The “shared track” class refers to tracks stored in Apple Music or iCloud, hence why your original script would only change the play counts of downloaded files.

Hope this helps either the OP or anyone else.

1 Like

Yes! That’s exactly the kind of answer I was looking for! Thanks!