How To Enhance iTunes with AppleScript

How To Enhance iTunes with AppleScript

Tutorial Details
  • Topics: iTunes, Automation, AppleScript
  • Difficulty: Intermediate
  • Estimated Completion Time: 25 Minutes

Many people would agree that iTunes is fast becoming (or has already become) bloatware. It has a ridiculous number of features and uses, but not always what we’d consider to be the right ones. You can find out what songs Bruno Mars is particularly enjoying at this time, and yet can’t search YouTube for music videos.

Luckily, everybody’s in the same boat, and people have been working tirelessly to create ways for you to make your iTunes work the way you want it to. Today, we’ll be focusing on DougScripts, a site started by Doug Adams a little over 10 years ago in February 2001, which is home to around 500 AppleScript files.

These scripts are free to download and easy to install. In this article, we’ll be showing you how to do just that, and showcasing some of Doug’s best work over the past 10 years.

Installing a Script

Installing an AppleScript script is just about as easy as you can get. If you want to follow along with this short tutorial, we’ll be working with Just Play This One, a script which plays a selected song in iTunes, instead of the whole album or playlist.

  1. Download the script, and uncompress the ZIP file.
  2. Open up the DMG. In this case, you will have all of the instructions laid out for you already, but if you download scripts from other sites, you are not always so lucky.
  3. Installing the Script
    Installing the Script
  4. Open up a second Finder window, and navigate to (your username)/Library/iTunes/Scripts. If you haven’t got a “Scripts” folder, which is likely, if you’ve never installed a script before, simply make one.
  5. Drag Just Play This One.scptd into your Scripts folder. You can put the instruction file in too, but it’s not necessary for the script to work.

Running a Script

  1. Bring up iTunes. There is no need to quit and reopen iTunes, the script will be loaded automatically.
  2. In the case of the “Just Play This One” script, select a song from an album or playlist, go into the AppleScript menu (A scroll icon in the menu bar), and click “Just Play This One”. iTunes will play the selected song and stop.
Running a Script
Running a Script

Every script is different, so you will use them differently. Check the instructions that come with the script on how to use the individual script. One thing which stays the same is that you run the script from the AppleScript menu.

Assigning a Keyboard Shortcut

Having to go through the menu bar every time you want to activate one of these scripts is time-consuming. Wouldn’t it much easier to use a keyboard shortcut? Here’s how:

  1. Take note of the exact wording of the command in the menu bar you want to add a shortcut to. All punctuation, capitals, etc. are essential for it to work.
  2. Close iTunes.
  3. Open System Preferences, and navigate to the Keyboard panel. Then, go to the Keyboard Shortcuts tab.
  4. Click on the “+” button and a panel will pop up.
    Setting a Keyboard Shortcut
    Setting a Keyboard Shortcut
  5. Select iTunes as the application.
  6. Type the exact command into the “Menu Title” field. In this example “Just Play This One”.
  7. Choose your keyboard shortcut. Try not to make it anything that will conflict with other shortcuts.
  8. Open iTunes again and use your shortcut at will.

20+ Great Scripts to Improve iTunes

Now that you know how to install and use scripts, it’s time to start building your script library. Here are over 20 of the most useful scripts from Doug Adams.

Super Remove Dead Tracks
“Dead tracks” are those in which the file is no longer locatable, and can be identified in iTunes by a “!” next to their name. This scripts gets rid of them from your library in one fell swoop.

Delete Tracks Never Played
Everybody has a number of songs with a play count of 0 which they have never listened to. Maybe, eventually, you’ll conclude that if you haven’t listened to it yet, you probably never will, and want to delete them. This script does it easily.

Import iPod Audio Files
If you somehow lose some songs from iTunes, but have them on your iPod, you can use this script to recover them. This won’t work for your entire library, but it should be able to handle an album or two.

Update Expired Podcasts
If you haven’t listened to a podcast for a certain length of time, iTunes will stop downloading updates. Use this script to update them again.

Change iTunes Hidden Preferences
There are a number of iTunes preferences which Apple have decided to hide, but you can access them with this script. You’ll be able to hide the Ping buttons, use half stars for ratings, and several more.

Change iTunes Hidden Preferences
Change iTunes Hidden Preferences

Gather Up the One-Hits
This script creates a playlist of the artists of which you only have one song by. Often, these  songs are crackers, so this is a very useful script.

Needle Drop
This can be used to play a certain length of every song before skipping to the next. If you have a low attention span, this could be for you.

Block Party
This app creates playlist of random songs, but in blocks of 2 or 3 songs by each artist. So you’ll get 2 songs by The Beatles, then 2 by Queen, 2 by Bowie, and so on.

Block Party
Block Party

Just Play This One
This is the script from our tutorial. As previously explained, it plays a single song and then stops, instead of a whole album or playlist.

Play Selected Track Next
This is a nice way to queue up a track. Simply select it while another track is playing, and run the script. The selected track will play after the current song has ended.

Now Where Was I?
This script remembers the song you played when you quit iTunes, and starts playing it again when you open iTunes again. It requires a little more work to get its full function, but it’s very useful if you put in the little bit of extra time.

Tracks Without Artwork to Playlist
This does exactly what it says on the tin – Places all tracks without any artwork into a playlist so you can work through them in your own time.

Remove n Characters from Front or Back
Sometimes, all tracks in an album will be named something along the lines of “07 – The Beatles – A Hard Day’s Night”. With this script, you can remove a certain number of characters from the front or back of a track name, in order to clean it up.

New Play Count
I like my play count to be an accurate representation of my favourite songs (it rarely is), and this script can assign new play counts to songs, if you had to re-import a song, or if you just wanted to hide how many times you’ve listened to that Hannah Montana soundtrack.

New Play Count
New Play Count

Rate Me! Rate Me!
This script reminds you to rate a song, whenever an unrated song is played. If you’re not in the habit of rating songs, this is a great way to start.

Sundry Info to Comments
What do you put in the Comments field in iTunes? If you’re like me, you won’t have much to put in there. This script allows you to put the file name, file path, sound volume, file creation date or a number of other details in the comments field.

Album to Album Artist
In most cases, except compilation albums, the artist field will read the same as the album artist field. With the script, you can quickly synchronise the two fields.

Proper English Title Capitalisation
If you’re anything like me, you want every little meta tag to be perfect, and poorly capitalised song titles will drive you to despair. This script will save you from a lifetime of frustration.

Search Wikipedia
No prizes for guessing what this does – It searches Wikipedia for the song, album, artist or composer of a selected song. Great for getting data for meta tags quickly.

Search Wikipedia
Search Wikipedia

Search YouTube
This too is pretty self-explanatory – It searches YouTube for the selected song. If you love music videos, this will be an essential download.

Guitar Tab Search
Can you guess what this script does? Yup, it finds guitar tabs on Ultimate Guitar for a selected song. How did you guess?

Music Trivia
This is less useful, more fun. It plays a snippet of a song, and you must guess the song.

Conclusion

As you can see, there are plenty of excellent scripts available, and that’s just on one website. Start exploring more websites and you’ll never need to manually edit a thing on iTunes ever again.

Considering how easy it is to install these scripts, and how much time they save, there’s no reason why you shouldn’t get started straight away!

Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
  • Emilysophia

    These are great! But do you have a script that searches for piano chords/notes as opposed to guitar chords?

    • Grant

      I bet you could open that script up in AppleScript editor and EASILY modify it to search some piano website instead of Ultimate Guitar. Even if you don’t know AppleScript, all you’d probably have to do here is swap out a URL.

  • Daniel

    The title parser I also find very useful (search for “parse”). It’s a quick way to assign all the correct metadata that is sometimes all jammed into the song title with badly tagged files.

  • Pingback: How To Enhance iTunes with AppleScript | Mac.AppStorm | Il Mac Minimalista

  • Pingback: How To Enhance iTunes with AppleScript | Apple | Keefer Madness

  • http://blog.hussein.me/ Hussein

    Seriously, how to remove duplicated items in iTunes?

  • Martin

    Hussein: I believe that the new iTunes can do that, go to File – Display Duplicates, now you can see only duplicates

  • Simon

    Hi, I am looking for a script to have my app purchase VIA itunes and download the playlist from itunes. Can this be done? I am ready to pay a good amount if anyone can handle this project. Let me know if theres anyone interested to develop

  • http://www.itrush.com IT Rush

    This is awesome, the step-by-step guide is simply easy to follow. TY.

  • http://www.amazeline.com/574 John Mac

    And just as I expected, we can only do it on Mac not on Windows. iTunes is also available in Windows, too, you know. :-)

    • http://www.coroflot.com/joshuajohnson Joshua Johnson

      Yep… but this is Mac.AppStorm ;)

  • Tobias Funder

    Awesome! Thanks a lot!

  • Larry Broadmoore

    Having spent some years in 1875-1920 or so, what passes for music since the Great War disturbs me somehow, so my iTunes library consists primarily of transcriptions of regular 78 rotation per minute talking machine selections, the rest consisting of electrically transcribed operas, symphonic and concert performances not available in better form.

    For popular music, there are no better selections and nowhere more enjoyable to hear, than those sung by Billy Murray, Ada Jones, the American Quartet et al; and this leads to the quandary to which I seek a solution.

    As anyone who has ever compared them knows, records played through a wooden horn on a talking machine in perfect order, as they were intended and engineered to be played, nearly always sound vastly better than the same recordings ever sound through the common arrangement consisting of a cone speaker energized by an electromagnet, which renders normally unnoticeable surface noise grotesque and unbearable. Yet, the selections available through the Internet Archive and others are so copious and would be so hard to find in shellac form, that we are strongly compelled to put up with listening to wonderful performances punctuated by frantic adjustments of iTunes’ equalizer for each recording.

    The situations vary so widely to which the source recordings were exposed before transcription, that it seems as though each needs greatly different settings. Some evidently have been “cleaned up” so well by engineering Wizards that only a connoisseur could tell. Some are inaudible due to surface noise.
    Further, the volume for each is annoyingly different.

    Could any existing software make this problem less of a distraction and annoyance? Or could one write scripts for that purpose?

    Many thanks,
    Larry Broadmoore