Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Traverse

macrumors 604
Original poster
Mar 11, 2013
7,724
4,512
Here
I am restoring my system to install Yosemite. I've had the same iTunes library for years and it has suffered some corruption/glitch. Every time iTunes is launched it must "Analyze Gapless Playback."

I can fix this by dragging the 4 library files to the trash and starting fresh with just my music, but then I loose my ratings and play count.

Is there a way I can quickly restore my play count without having to sit their tediously and click through each song?
 
  • Like
Reactions: suckerformayhem
I had to write some AppleScript way back (almost 5 years now) for someone who was having Library issues just like you are.

Attached is a zip file with three scripts:

  • info_into_comments - saves playcount and rating into the comment metadata field
  • info_out - extracts playcount and rating from comment field
  • clear_comments - sets comments to blank

You install them by copying them into your ~/Library/iTunes/Scripts folder. If it doesn't exist, then create it. Alternatively, if you have a little script icon in iTunes Menu Bar to the right of 'Window', the top menu will take you there as well.

These scripts have a prerequisite that you don't use the comments field in your music files because they will be replaced.

Instructions:
  1. Select all music in library
  2. Run 'into comments' (store the metadata)
  3. Trash your library files (this is where you lose the playcounts)
  4. Restart iTunes
  5. Run 'info out' (get back your playcounts)
  6. Run 'clear comments' (housecleaning)

EDIT: you could write a version that preserves any comments you might already have. Unfortunately, I'm a little strapped for time atm
 

Attachments

  • itunes info.zip
    5.5 KB · Views: 150
Last edited:
  • Like
Reactions: suckerformayhem
I had to write some AppleScript way back (almost 5 years now) for someone who was having Library issues just like you are.

Attached is a zip file with three scripts:

Thank you! I'm also playing with some of "Doug's AppleScripts" and, forgive me for being paranoid, but how do I know that none of his are malicious?
 
Thank you! I'm also playing with some of "Doug's AppleScripts" and, forgive me for being paranoid, but how do I know that none of his are malicious?

You should be able to open them in Script Editor to view the scripts.

But I'll post them here anyway. You can recreate the scripts yourself.

"Save Into Comments"
Code:
tell application "iTunes"
	if selection is not {} then
		set sel to selection
		repeat with t in sel
			set t to contents of t
			if class of t is file track or class of t is URL track then
				set comment of t to played count of t & "
" & rating of t as string
			end if
		end repeat
	end if
end tell

"Restore from Comments"
Code:
tell application "iTunes"
	if selection is not {} then
		set sel to selection
		repeat with t in sel
			set t to contents of t
			if class of t is file track or class of t is URL track then
				set content1 to comment of t
				set content2 to words in content1
				set played count of t to item 1 in content2
				set rating of t to item 2 in content2
			end if
		end repeat
	end if
end tell

"Clear comments"
Code:
tell application "iTunes"
	if selection is not {} then
		set sel to selection
		repeat with t in sel
			set t to contents of t
			if class of t is file track or class of t is URL track then
				set comments of t to ""
			end if
		end repeat
	end if
end tell

Note: I wrote these way back before I was any kind of serious programmer. There is some room for improvement, if you want to do it yourself, non-destructive comments can be added.
 
  • Like
Reactions: suckerformayhem
Thank you! I'm going to save these.

I appreciate it because I'm not experienced with scripting (yet).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.