Fix Genres AppleScript
The AppleScript below corrects genres in the free iTunes Sampler albums in your iTunes library. It is for personal use by MacRumors members.
To use this script:
- If you have not already done so, download one or more "iTunes Samplers" from the iTunes Music Store. See the beginning of this thread for the links.
- Copy all text in this post, starting with the --copy me-- line and ending with the --stop copying me-- line, to the clipboard.
- Open Applications/AppleScript/Script Editor.
- In the empty Script Editor window, paste the script from the clipboard.
- Optional: Click the Compile icon. The AppleScript will be displayed with proper formatting.
- Click the Run icon. The AppleScript will be executed.
- Reply to the prompts.
- Quit Script Editor without saving the script.
- If you have another Mac, repeat these instructions.
--copy me--
-- Fix Genres (AppleScript)
-- Author: Doctor Q, MacRumors.com
-- Version: 1.0, February 2005
-- Format: Distributed as AppleScript source code.
-- Availabilty: Free to MacRumors forum members. Not to be further distributed.
-- Warranty: None. Use at your own risk.
-- The purpose of this AppleScript is to correct the genre settings for the free "iTunes Sampler" albums in the iTunes Music Store.
-- As offered by Apple, these Samplers have had the genre for all tunes mistakenly set to "Pop".
-- Fix Genres version 1.0 covers these iTunes Samplers:
-- 1. iTunes New Music Sampler (Universal Motown Edition)
-- 2. iTunes New Music Sampler (Atlantic/Lava Edition)
-- It is OK to run the script multiple times and to Quit at any time.
-- General cautions:
-- You should not run programs or scripts without some assurance that they are safe.
-- Consider the source and/or examine the source code yourself before using a program or script that you download from the Internet.
-- You should routinely back up your iTunes library, and it is also wise to back it up before running programs that can affect it.
-- Start of Applescript
-- fixalbum: routine to fix the genres of tracks of a given album
-- arguments: album name, list of {artist, name, correct genre, optional-comments}
on fixalbum(thealbum, tracklist)
if havealbum(thealbum) then
tell application "iTunes" to display dialog "Do you want to fix genres in " & thealbum & "?" buttons {"Skip Album", "Fix Genres"} default button "Fix Genres"
if the button returned of the result is "Fix Genres" then
set nchanged to 0
set changes to "Changes made to " & thealbum & ":"
repeat with thetrack in tracklist
set theartist to item 1 of thetrack
set thename to item 2 of thetrack
set newgenre to item 3 of thetrack
set oldgenre to fixtrack(theartist, thename, newgenre)
if oldgenre is not "" then
set nchanged to nchanged + 1
set changes to changes & return & (nchanged as string) & ". " & thename & " by " & theartist & ":" & return & "" & "" & "" & "" & "" & oldgenre & " -> " & newgenre
end if
end repeat
tell application "iTunes"
if (nchanged = 0) then
display dialog "No changes were made to " & thealbum & "." buttons {"OK"} default button "OK" with icon note
else
display dialog changes buttons {"OK"} default button "OK" with icon note
end if
end tell
end if
else
tell application "iTunes" to display dialog thealbum & " is not in your library, so it will not be checked." buttons {"OK"} default button "OK" with icon caution
end if
end fixalbum
-- fixtrack: routine to fix the genre of one track
-- arguments: artist name, song name, correct genre
-- return value: string: old genre if changed, null otherwise
on fixtrack(theartist, thename, newgenre)
set returnvalue to ""
tell application "iTunes"
tell playlist "Library" of source "Library"
set matchingtracks to (every track whose artist is theartist and name is thename)
set nmatches to count of matchingtracks
if nmatches is 0 then
display dialog ("Track '" & thename & "' by '" & theartist & "' was not found.") with icon caution
else
repeat with thetrack in matchingtracks
set oldgenre to the genre of thetrack
if oldgenre is not newgenre then
set the genre of thetrack to newgenre -- the only permanent action of this script
set returnvalue to oldgenre
end if
end repeat
end if
end tell
end tell
return returnvalue
end fixtrack
-- havealbum: routine to test if an album is present
-- argument: album name
-- return value: Boolean: is album in library?
on havealbum(albumname)
tell application "iTunes"
tell playlist "Library" of source "Library"
return exists (first track whose album is albumname)
end tell
end tell
end havealbum
-- Main program:
-- iTunes New Music Sampler (Universal Motown Edition)
fixalbum("iTunes New Music Sampler (Universal Motown Edition)", {¬
{"Features", "Blow It Out", "Alternative"}, ¬
{"Jamie Cullum", "All at Sea", "Jazz"}, ¬
{"Miri Ben-Ari", "Sunshine to the Rain", "Hip Hop/Rap"}, ¬
{"Akon", "Lonely", "Hip Hop/Rap"}, ¬
{"Razorlight", "Golden Touch", "Rock"}, ¬
{"Brian McKnight", "Every Time You Go Away", "Rock"}, ¬
{"The Soundtrack of Our Lives", "Bigtime", "R&B/Soul"}, ¬
{"Scissor Sisters", "Laura", "Pop"}, ¬
{"Brie Larson", "She Said", "Pop"}, ¬
{"O'Ryan", "Jus Anotha Shorty", "R&B/Soul"}, ¬
{"Teitur", "Sleeping with the Lights On", "Rock"}, ¬
{"Michael McDonald", "Reach Out, I'll Be There", "R&B/Soul"}, ¬
{"Le Tigre", "TKO", "Electronic"} ¬
})
-- iTunes New Music Sampler (Atlantic/Lava Edition)
fixalbum("iTunes New Music Sampler (Atlantic/Lava Edition)", {¬
{"Death Cab for Cutie", "Title and Registration", "Alternative"}, ¬
{"Simple Plan", "Welcome to My Life", "Alternative"}, ¬
{"Gratitude", "Drive Away", "Alternative"}, ¬
{"Ellie Lawson", "Gotta Get Up from Here", "Pop"}, ¬
{"Unwritten Law", "Lost Control", "Rock"}, ¬
{"John Butler Trio", "What You Want", "Rock"}, ¬
{"No Address", "When I'm Gone (Sadie)", "Rock", "Note: my opinion", "Note: my opinion"}, ¬
{"Rock 'n' Roll Soldiers", "Funny Little Feeling", "Soundtrack", "Alternative", "Note: Alternative"}, ¬
{"The Stills", "Yesterday Never Tomorrows", "Rock"}, ¬
{"Louis XIV", "Louis XIV", "Alternative"}, ¬
{"Moments In Grace", "Broken Promises", "Rock"}, ¬
{"The Kinison", "You'll Never Guess Who Died", "Alternative"}, ¬
{"Skindred", "Pressure", "Rock"}, ¬
{"The Format", "On Your Porch", "Rock"}, ¬
{"Toby Lightman", "Everyday", "Pop"}, ¬
{"Porcupine Tree", "Shallow", "Alternative"} ¬
})
tell application "iTunes" to display dialog "Fix Genres complete." buttons {"Quit"} default button "Quit"
-- End of AppleScript
--stop copying me--