Using AppleScripts with iTunes

AppleScript-icon.pngI write a lot about using AppleScripts with iTunes. Thanks to iTunes’ scriptability, it is possible to extend the app with numerous features and shortcuts. If not for Doug Adams, the master scripter and proprietor of Doug’s AppleScripts for iTunes, I would spend a lot more time managing my iTunes library.

I often mention AppleScripts in my Ask the iTunes Guy column over at Macworld, since Doug’s scripts make a lot of seemingly complicated maneuvers a matter of a few mouse clicks. In this week’s column, which I just finished writing, I mention two AppleScripts, and I thought it would be useful to talk a bit about AppleScript and discuss how you use AppleScripts with iTunes.

AppleScript is a scripting language that Apple developed for the Macintosh operating system in the early 1990s. It was first available on System 7.1.1, and it offers a way to take advantage of system functions via AppleScripts, short programs that are much easier to write than full-fledged applications.

AppleScript works with much more than just the operating system: many Apple programs (the Finder, iTunes, iPhoto, Safari, Mail, etc.) and third-party applications (Microsoft Office, Adobe Creative Suite, etc.) support AppleScript to some extent. But none more than iTunes.

AppleScript support can be limited—supporting a mere handful of commands—to complex. iTunes is one of those programs that offers in-depth scriptability, notably by providing access via AppleScript to the tags in your media files.

When you add AppleScripts to your ~/Library/iTunes/Scripts folder (that’s the Library folder in your home folder, the one with your house icon and your user name), they display in a Scripts menu in iTunes, and you can run them by choosing them. To access this folder, in the Finder, press the Option key, choose the Go menu, then choose Library. Next, find the iTunes folder there, and open it. If you have any AppleScripts, you’ll have a Scripts folder; if not, you’ll need to create one.

When you download any AppleScripts from Doug’s site, you place them in the above folder. Once they are in that folder, iTunes sees them. You’ll see a script icon in the menu bar, right before the Help menu.


For some scripts, you select one or more tracks; for others, you select a playlist. After you’ve selected the items the script is to run on, you click the scroll icon and select the script’s name.

That’s all there is to it. Make sure to check out Doug’s AppleScripts for iTunes to see what you can do with AppleScript, and don’t forget to donate to Doug Adams, who’s written hundreds of AppleScripts to help make iTunes better.

Share this article:Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

Re-Ripping CDs with iTunes

You may occasionally want to re-rip one or more CDs that you own. One of the most common reasons for this is to rip CDs at a higher bit rate than you did back when disk space was more limited.

Wen you do this, you may want to ensure that you don’t lose metadata for the existing files. Not just the names of the tracks, albums and artists, but also information like play counts, artwork and ratings. If you do this carefully, you can ensure that when you re-rip CDs, you keep all the metadata.

The first thing you should know is that, if you rip a CD, and you already have the tracks in your iTunes library, iTunes will alert you to this, asking if you want to replace the existing tracks:


This is, in fact, what you want to do when re-ripping CDs. When iTunes replaces existing tracks, it only replaces the music. It retains all the other metadata, and it keeps the tracks in any playlists you’ve created. (If you re-rip and add the tracks to your iTunes library anew, then delete the old ones, these tracks will no longer be in playlists, though they will be in smart playlists.) But iTunes can only replace existing tracks if all the metadata matches.

So if you want to re-rip a CD, and have iTunes replace the music, you need to ensure that all the tags – the ones you can change – are the same. These are Name, Album, Artist, Genre, Year, Disc Number, Composer, Grouping, Album Artist and Comments. If any of these are different – if there’s even a comma or different capitalization – iTunes will think the track is different.

When you insert the CD, and examine it in iTunes, you can check the tags, comparing them to the existing files. You can correct any differences manually, or you can use Doug Adams’ Copy Tag Info Tracks to Tracks AppleScript. Read the information on Doug’s site to find out how to use this script.

I find it best to rip CDs by dragging their tracks to a “Temp” playlist; this lets me examine the tracks without having to find them in my iTunes library. If you want to re-rip CDs, I recommend making another playlist with their tracks, then checking that playlist after you rip each CD. You should see the tracks have been replaced. So, if you had tracks at 128 kbps, and you’re re-ripping them at 256 kbps, you’ll see the new bit rate in the playlist.

If you follow this procedure when re-ripping CDs, you’ll find that you save a lot of time: not only do you not have to manually update tags, but you also retain all the metadata that you can’t edit.

Share this article:Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

iTunes 11: AppleScript to Edit Tags of Multiple Media Types

Update: Apple fixed this in iTunes 11.1.2.

I recently posted an article pointing out that, in iTunes 11.1, you can no longer edit tags of multiple media items. As I explained:

“Let’s say you’ve just bought some music by download: from the iTunes Store, or from any other purveyor of digital music. You may get more than just music: you may get a digital booklet (a PDF file replicating liner notes), or even a music video. These are different types of media: the music is audio files, the digital booklet is a PDF, and the video is, well, a video.

“Previously, you could select all these items and tag them. So if you wanted to change the album or genre tag, for example, for the music, PDF and video, you could do it all at the same time. After all, you probably want the PDF to be stored in your Music library, which makes it easy to find. (That’s where digital booklets go, by default.)”

Well, I got in touch with Doug Adams, of Doug’s AppleScripts for iTunes, to see if he could whip up an AppleScript to solve this problem. Being the fast worker that he is, Doug whipped up an app called Multi-Media Items Edit. This script “provides basic tag editing for a selection of tracks of any media kind.”


Select some tracks in iTunes, run this script, and you’ll be able to assign a number of tags to all the items. You can do this with any combination of items: music, books, digital booklets (PDF files), movies, etc.

Thanks to Doug for coming up with such a quick solution. This isn’t a problem that a lot of people will face often, but it’s a time-saver if you want to work with different types of files and change their tags.

Share this article:Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

App of the Week: Dupin Lite Culls Duplicates in Your iTunes Library

One question I get a lot from iTunes users is this: how can I remove duplicate tracks from my iTunes library? iTunes has a feature that can display duplicates, but it’s not very good. If you choose View > Show Duplicate Items, iTunes will analyze your library, then show any items that it thinks are duplicates. The problem is that it only checks for dupes by looking at a track name and artist name. If you have, say, studio and live recordings by certain artists, those tracks will show up as duplicates.

Doug Adams’ $8 Dupin Lite does what iTunes can’t: it allows you to check by multiple criteria, and also by the ones you want. So you could look by, say, track name and artist and time, to find tracks of exactly the same length. Or you could look by track name and bit rate, so, if you have files in two formats (such as lossless and compressed), it won’t match those tracks.


When you want to cull your iTunes library, and check for dupes, Dupin Lite is the best place to go. While you’re at it, check out the Doug’s AppleScripts for iTunes web site, where Doug Adams has hundreds of AppleScripts that can help you manage files, tags, tracks and much more in your iTunes library. I couldn’t live without Doug’s scripts.

Share this article:Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

AppleScript to Toggle Between Stereo and Mono Output

It’s not often that you’d need to switch your Mac’s audio output from stereo to mono, but you may want to do so in certain situations. Doug Adams has a nifty Toggle Stereo/Mono Output AppleScript on his website today. If you ever need to make that switch, you can use this script to do it on the fly, rather than going to the System Preferences, where it’s a setting that’s not easy to find.

Share this article:Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

Use LaunchBar to Launch AppleScripts for iTunes

One of the best ways to extend functionality of iTunes is through AppleScripts. These routines allow you to manipulate tags and files, and save me a huge amount of time when I’m ripping CDs and need to tag items, and when I’m working with my iTunes library. Doug Adams’ website Doug’s AppleScripts for iTunes is the place to go to find great scripts that can save you a lot of time, and do things you simply cannot do from iTunes.

Launching AppleScripts from iTunes involves putting the scripts in a special folder (located at ~/Library/iTunes/Scripts), and choosing them from a script menu that displays in the iTunes menu bar:


The AppleScript menu is that little squiggly thing (a scroll) in the menu bar.

But there’s another way to launch AppleScripts in iTunes, using Objective Development’s LaunchBar, a powerful launcher that you control from the keyboard. Here’s how.

(If you use LaunchBar, check out my recent book, Take Control of LaunchBar.)

First, you need to add the Scripts folder to LaunchBar. Press your LaunchBar keyboard shortcut, then click on the gear icon and choose Index > Show Index, or press Command-Option-I. You’ll see something like this:

Launchbar index

Click on the + icon at the bottom of the window, choose Add Folder, then navigate to ~/Library/iTunes/Scripts; ~ is a shortcut for your home folder, the folder that has your user name. The LaunchBar index window will show all the scripts in that folder. (You’ll note that there is already a Scripts folder in LaunchBar’s index; this is a different folder, located at ~/Library/Scripts.)

Press Command-0 to update the LaunchBar index, then close the window and save your changes.

Now, in iTunes, when you want to launch a script, do the following:

1. Press your LaunchBar keyboard shortcut.

2. Type “scr” and use the arrow keys to navigate to the correct folder. If the other Scripts folder is in the menu, make sure not to select that one.

3. Once you’ve selected the correct Scripts folder in the LaunchBar menu, press the space bar. This will display a menu with all your scripts.

4. Now, you can either use the arrow keys to choose the script you want to run (press Return when you’ve selected it), or type an abbreviation to get to it. LaunchBar will find the script if you type a few letters of its name, using its sub-search feature.

Launching scripts in this manner merely saves you from accessing the scripts menu in iTunes, but if you like to keep your hands on the keyboard, it will save you a few clicks. If you run certain scripts often, it is a good way to get to them quickly.

(By the way, I was prompted to write this after reading Doug Adams’ post about using TextExpander to launch AppleScripts for iTunes.)

Share this article:Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

Playlist Assist Replicates Old iTunes Playlist Window

One of the things that irked many users when iTunes 11 was released was the inability to open more than one window. Some users kept an iTunes Store window open all the time; others liked to open playlists in their own windows, to make it easier to drag tracks to them and edit their contents.

AppleScript maestro Doug Adams has released the $5 Playlist Assist, a new tool which replicates some of the old iTunes playlist window features. Playlist Assist gives you a floating window that you can use to create and edit playlists. But you can also get track info, change tags, play tracks using Quick Look, and export playlists.


I’ve been using this for a while in beta, and I’m quite impressed by its flexibility. If you want a great tool for creating and editing playlists, you need Playlist Assist.

Share this article:Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn

iTunes, Full-Screen View and AppleScript Applets

One of the marquee features in OS X Lion is full-screen view. Using this, your menubar withdraws from the screen, and your window takes up a tad more space. I don’t use this much on my 27″ iMac – may main computer – with the exception of for iTunes. Regular readers of this blog know that I’m a big music fan, and have a huge iTunes library. (Currently about 75,000 tracks.) With iTunes in full-screen view, I can eke out a bit more space to view my music.

I’m also an obsessive tagger. Whenever I add music to my iTunes library, either by ripping CDs or by adding downloads, I ensure that the tags fit my personal tagging scheme. To do this, I use a number of AppleScripts from the Doug’s AppleScripts for iTunes web site.

Doug Adams recently updated a script I use often, Remove n Characters from Front or Back, turning it into a nifty applet which is far more useful than previous incarnations. Unfortunately, when using iTunes in full-screen mode, applets simply don’t work well. Since they spawn their own windows, they can’t display over the iTunes window, and bounce to another space. This is a shame; when I want to use such applets, I need to take iTunes out of full-screen mode.

This behavior can be confusing. Fortunately, Doug came up with a dialog explaining this to users. His applet detects when iTunes is in full-screen mode, and, if so, shows the following:

This means that users have to either move the applet’s window back to the iTunes space, but it’s actually easier to take iTunes out of full-screen mode. It’s a shame that AppleScript works this way. This will be the case for a number of applets, and is especially unfortunate because AppleScript, in Lion, can access Cocoa frameworks, and create applets that can do much more than previous versions of AppleScript.

Share this article:Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedIn