Swap Song Name and Artist

Correct that irritating problem of’ song names and artist names being reversed.

The first time you find a track in iTunes that somehow has gotten its Song Name and Artist reversed, you open up its Get Info window and do some cutting, copying, pasting, and typing to effect repairs. It’s kind of a drag. When you see the same problem with another track, you begrudgingly do the swap a second time and hope that you won’t have to go through all that again. But when you notice it a third time, don’t lose your temper. Just break out the AppleScript.

The Code

This script gets the text from the nameand artistproperties of each of the selected tracks—or, if no tracks are selected, all the tracks in the selected playlist—and swaps them:

	tell application "iTunes"
	 -- act on particular tracks or all tracks currently displayed
	 if selection is not {} then
	   set sel to selection
	 else
	   set sel to file tracks of view of front window
	 end if

	 -- loop through each selected track
	 repeat with aTrack in sel
	   tell aTrack
	     set temp1 to (get name)
		 set name to (get artist)
		 set artist to temp1
		end tell
	  end repeat
    end tell

The first thing the script does is determine which tracks the user has selected for swapping. If none are selected, the script acts on all the tracks of the currently selected playlist. In either case, the list of tracks to be acted upon by the script is stowed away in a variable ...

Get iPod and iTunes Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.