DIY
Delete Other Artwork
iTunes is able to accommodate more than one image for a track entry's artwork. What hasn't always been obvious is that the first artwork in an array of artworks in a track is the "display" artwork. Any additional artwork in the artworks array are spares. Modern versions of the iTunes Get Info Artwork panel now label images as "Album Artwork" and "Other Artwork".
Some people think that these "Other Artwork" have to go.
It is a simple matter to simply remove the other artwork from a track entry with an AppleScript. Here's one now that goes through each track in a selection and repeats through its artworks (if there's more than one artwork), removing the last artwork until there is only the first one left:
tell application "iTunes"
set selectedTracks to selection of front browser window
repeat with i from 1 to (count of selectedTracks)
set thisTrack to item i of selectedTracks
tell thisTrack
try
if (count of its artworks) > 1 then
repeat until ((count of its artworks) is 1)
delete its last artwork
end repeat
end if
end try
end tell
end repeat
end tell
Click the script icon above to download this script to Script Editor at your house and click "New Script" to allow it to open. Save it named whatever you like in your ~/Library/iTunes/Scripts/ folder (or wherever you put them). Select some tracks in iTunes and launch the script.
There's always the kid in the front who wants to know why you don't make a script like this that just works on the entire library. Well: iTunes can be kind of touchy when AppleScripting a large amount of artwork stuff. It may "go modal" as it updates its database and under such circumstances may block an AppleScript from continuing its operation. So I purposely used the selection object so that the script can be used piecemeal on a small batch of tracks at a time. Additionally, you might want to eyeball the "Other Artworks" of a track before you start blindly mowing them all down; in which case having to select the tracks manually compels you to be in control.
The routines are in a try block to skip over errors because of what I mentioned above about modality and also in case there's some image gunk in there that causes trouble. Because images downloaded from the internet that you use as album artwork are always pristine, right?
Play Selected Track and Cue Next
A Correspondent inquired about a script that would play a selected track in iTunes through to the end and then stop and then select the next track but not play it. In such a way, a playlist containing sequential musical cues required for a theatrical performance could be fired one track at a time, via the script, without a lot of stopping and mouse-clicking and swearing backstage ("Up yer scrim!", "Purple behind!").
This is such a script:
-- Play Selected Track and Cue Next
tell application "iTunes"
-- get the single selected track and play it
set theSelection to selection
if length of theSelection is 1 then
set theTrack to item 1 of theSelection
try
play theTrack with once
on error
## beep
return
end try
-- the selected track is playing, now do some other stuff...
-- get the playlist
set thePlaylist to (get view of front window)
-- stash current fixed indexing value
set curfi to fixed indexing
-- we want free indexing not fixed indexing
set fixed indexing to false
-- compute next track's index
set idx to (get index of theTrack)
if (idx = (count of tracks of thePlaylist)) then
set idx to 1
else
set idx to (idx + 1)
end if
-- select the next track in the playlist
reveal track idx of thePlaylist
-- restore fixed indexing to whatever it was before
set fixed indexing to curfi
end if
end tell
What you'd want to do is save this with Script Editor, named whatever you like, with a File Format of "Script" and put it in your [Home]/Library/iTunes/Scripts/ folder so it appears in iTunes' Script menu.
Prepare a playlist and select its first track. When it's time to actually play the track, don't use any iTunes play controls; instead, fire the script. The script will play the selected track, figure out which track is next in sequence, select it, and then quit. iTunes will stop when the current track has finished by virtue of that with once parameter on the play command. When it's time to play the next track, which is now the selected track, fire the script to play it and select the next track. And so on.
While assigning this script a keyboard shortcut will be convenient if you can keep a hand near the keyboard, something that could fire this via a physical remote control would be super boss. Under such circumstances, you may prefer—or it may be necessary—to save the script with a File Format of "Application".
Spotify Artwork
Remember that script I posted a while back that exports the currently playing iTunes track's artwork?
Well, this one works with Spotify's desktop app:
tell application "Spotify"
try
if player state is not stopped then
set alb to (get album of current track)
set rawData to (get artwork of current track)
else
return
end if
on error
display dialog "Problem getting track info." buttons {"OK"}
return
end try
end tell
try
set baseLoc to choose folder
on error
return
end try
set newPath to ((baseLoc as text) & (my replaceChars(alb, ":", "_")) & ".tiff") as text
try
set fileRef to (open for access newPath with write permission)
write rawData to fileRef starting at 0
tell me to close access fileRef
on error m number n
log n
log m
try
tell me to close access fileRef
end try
end try
on replaceChars(txt, srch, repl)
set text item delimiters to srch
set item_list to every text item of txt
set text item delimiters to repl
set txt to item_list as string
set text item delimiters to ""
return txt
end replaceChars
Spotify has a pretty basic sdef but you can get some info from the current track, including artwork.
Blanking the Genre Tag in iTunes 12
Kirk has found a bug in iTunes 12 whereby selecting a batch of tracks and deleting their Genre tag via the Get Info panel inserts 8 spaces instead of empty text into each track's Genre tag. This creates a Blank Genre that is actually displayed and selectable in Genre lists.
This AppleScript will correctly delete the Genre tag of each track in a selection:
tell application "iTunes"
set sel to selection
repeat with thisTrack in sel
tell thisTrack to set its genre to ""
end repeat
end tell
Also, any number of other scripts that can edit the Genre tag, like Multi-Item Edit, will get the job done.
Save Current Track's Artwork
I don't know why you'd want to do this on any kind of regular basis, but I thought it was kinda fun for a Friday afternoon. I wanted to see if I could save artwork from iTunes Radio tracks, but it works with whatever the current track is:
tell application "iTunes"
try
if player state is not stopped then
set alb to (get album of current track)
tell artwork 1 of current track
if format is JPEG picture then
set imgFormat to ".jpg"
else
set imgFormat to ".png"
end if
end tell
set rawData to (get raw data of artwork 1 of current track)
else
return
end if
on error
display dialog "Problem getting track info." buttons {"OK"}
return
end try
end tell
try
set baseLoc to choose folder
on error
return
end try
set newPath to ((baseLoc as text) & alb & imgFormat) as text
try
tell me to set fileRef to (open for access newPath with write permission)
write rawData to fileRef starting at 0
tell me to close access fileRef
on error m number n
log n
log m
try
tell me to close access fileRef
end try
end try
Open that in Script Editor and "Save..." it as "Save Current Track's Artwork" (or whatever) in your ~/Library/iTunes/Scripts/ folder. Whenever a track is playing, you can launch it to choose a folder in which to save the current track's artwork. Great way to fill up your desktop with effluvia. (I'm kidding. But it would be good for that.)
More iTunes Power Search at Your Fingertips
[UPDATE: In iTunes 12.2 and later, selecting "Music" in this script will go to the "New" section of Apple Music. The other kind selections work as expected.]
Kirk has noticed that Apple has spruced up the iTunes Power Search page. Inspired, I improved this simple AppleScript to launch a Power Search by kind (click the AppleScript Editor icon below the code to display the code in AppleScript Editor on your machine):
set chooseOptions to {"All Results", "Apps", "Music", "Movies", "TV Shows", ¬
"Podcasts", "Books", "iTunesU"}
set optList to {"mt=3", "mt=8", "mt=1", "mt=6", "mt=4", "mt=2", ¬
"media=books#powerSearch&restrict=false&submit=media", ¬
"institutionTerm=&media=iTunesU"}
set opt to (choose from list chooseOptions with prompt "iTunes Power Search...")
if opt is false then return
repeat with i from 1 to length of chooseOptions
if opt as text is (item i of chooseOptions) then
set opt to (item i of optList)
end if
end repeat
set link to ("itms://phobos.apple.com/WebObjects/MZSearch.woa/wa/advancedSearch?" & opt) as text
tell application "iTunes" to open location link
Save that as something like "Power Search" in your ~/Library/iTunes/Scripts/ folder and assign it a shortcut. When you launch it, you can select the area you want to search:

Reveal Multiple Selected Tracks' Files
I occasionally have need to access the files of tracks that may not always be in the same "Album" folder. iTunes has a "Show in Finder" command (Shift-Command-R) for single tracks so to reveal all the files from disparate folders I have to "Show in Finder" each of the tracks, one at a time.
But what if I could open each selected track's file's folder in its own tab in a single Finder window? Like this:

Each tab is the containing folder for the file of each selected track and each file is highlighted. Even if two or more files are in the same folder the folder will get its own tab for each file.
The script follows:
(more…)
Search iTunes Store via Google
Kirk had a tip about using Google to search the iTunes Store in his Macworld column today. Here's a script for that:
try
set searchText to text returned of (display dialog "Search the iTunes Music Store for:" default answer "")
tell application "Finder" to open location "http://www.google.com/search?q=site:itunes.apple.com " & searchText
end try

Launch and enter some search text and click the "OK" button. A new window with Google results will be displayed by your default browser.


