Mimsy Were the Borogoves

Hacks: Articles about programming in Python, Perl, PHP, and whatever else I happen to feel like hacking at.

Run a script on inserting an audio CD

Jerry Stratton, May 7, 2006

Preflighting vinyl import was pretty easy, because for vinyl import, I was already using an AppleScript to do the import. However, I have the same problem when importing CDs: if I recently converted a podcast to MP3 mono and forgot to change it back, I’ll end up accidentally importing CDs as low quality mono rather than high quality stereo.

It isn’t that big of a deal, because iTunes will recognize when you re-import a CD you’ve imported before. It will ask if you want to replace the existing files, and if you say yes, it will copy all of the information over to the new, better files: play count, last played, names, ratings, even album cover if you’ve put one onto the tracks.

But it would be nice to get a warning when I’m about to import an audio CD at poor quality similar to the warning I get when I’m about to import vinyl at poor quality. Fortunately, there is an easy way of running our own script whenever we insert an audio CD.

Back when you first got your Macintosh, you might remember that sometimes, on inserting media, the Mac would ask you what you want to do with that media. The Mac then stores your preference for future use. You can reset these preferences in your System Preferences. Choose “CDs & DVDs” from the Hardware row. You can choose one of your scripts for what to do “When you insert a music CD”.

The script must be saved as File Format script, not as an application.

[toggle code]

  • on run
    • tell application "iTunes" to set theEncoder to the format of the current encoder
    • if theEncoder is not "AAC" then
      • display dialog "iTunes is not set to use AAC"
      • return
    • end if
  • end run

Obviously, if you prefer MP3 you’ll change that as your encoding format. Unfortunately, I can still find no way to check the bit rate.

In response to Preflight iTunes Imports: Once you start using an AppleScript to do automated tasks, you can also more easily preflight those tasks to make sure that everything is okay on all ends.