Controlling iTunes

January 20 2012 - 10:40 am

UPDATED: Play Random Album v3.0

A Particular Correspondent noticed that the previous version of Play Random Album was biased towards larger albums when selecting one at random. The problem was that it grabbed a random track first and built the album out using the album of that track. Well, of course. Albums with more tracks had a better chance of being selected by virtue of having more tracks in the pool, as it were.

The latest version of Play Random Album actually chooses a random album name first which gives every album a fair chance. I've also speeded it up a little and tweaked some error checking. Attach it to a keyboard shortcut and it almost feels native.

I just bought a set of Bose 201 speakers and I've been burning 'em in (ahem, letting them experience a variety of frequencies) by playing random albums using this script. Works great.

December 12 2011 - 11:37 am

UPDATED: Update Expired Podcasts v2.2 (and launchd project)

iTunes will stop updating a Podcast subscription if you haven't played at least one of its episodes in five days. Update Expired Podcasts v2.2 will go through every Podcast subscription and update it so you don't have to manually update each one individually.

This latest version adds a routine that checks to see if iTunes is running before proceeding with updating the Podcasts. Now, you may be asking yourself: if I'm running the script from the iTunes Script menu then why would the script need to check if iTunes is already running? Because: I'm going to show you how to regularly launch the script automatically and invisibly in the background and you may not want iTunes to run when the script fires. If you're not familiar with launchd then read on.


October 25 2011 - 8:14 pm

Name New Playlist From Selection

I use the "New Playlist from Selection" command a lot to create temporary playlists. Actually, I use the Shift-Command-N shortcut more often than clicking the command in the File menu. But I'm irritated at all the dancing I have to do to name the new "untitled playlist". It takes my attention away from what I was intending to do with the tracks. So, I rigged the script below to the keyboard shortcut Shift-Command-N—it works, luckily; sometimes assigning a shortcut that iTunes is already using doesn't override the original command. The script does exactly what "New Playlist from Selection" does except now I can enter the name for the playlist before it's created.

Here's the script:

September 28 2011 - 8:59 am

Column Browser Go Home

I've found that iTunes' Column Browser feature is one of the best ways to navigate the Music library. But I'm often annoyed that I can't easily restore the browser window to a full view of tracks after digging down to a particular set of tracks. To do so requires a lot of scrolling up and clicking. Correspondent Josh Rafofsky emailed me complaining of the same frustration and his solution was pretty good: Command-B to Hide the Column Browser, fn-Left Arrow to got to the top of the browser, and the Command-B again to Show the Column Browser. But even this gets tiresome and he asked if there might be a one-step scripting solution.

You know there is.

I put together this script which uses a combination of standard AppleScripting and GUI Scripting to emulate Josh's shortcuts solution:

tell application "iTunes" to activate
tell application "System Events"
	key code 11 using command down
	tell application "iTunes" to reveal track 1 of (get view of front window)
	key code 0 using {command down, shift down}
	key code 11 using command down
end tell

Save this as whatever you like—I call it "Column Browser Go Home"—save it to the ~/Library/iTunes/Scripts folder, and assign it a shortcut (make sure you have enabled GUI Scripting, too, as outlined in this article on using key codes). When launched after you've Column Browsed to a discrete set of tracks it will restore the entire list of tracks and jump to the top of the selected playlist. In my case this is usually the Music library playlist, but it will work with any playlist that's being viewed with the Column Browser.

[UPDATE] And after all that, @tonyhazeldine tweets: "The same can be done by clicking on the column titles at the top of the column browser." Yes, but each column has to be clicked.

September 12 2011 - 9:37 am

NEW: Play in Album Context

You can probably imagine that I hear a lot of unusual ideas for creating workflows for iTunes with AppleScript. Quite a while ago someone suggested a script that could be run when a track was playing that would find all the tracks of that track's album, put them in track order in a new playlist, and then play them in order starting from the original selected track. For example, "Time" from Dark Side of the Moon comes up and you want to hear "The Great Gig in the Sky", "Money", etc, in their album context.

But really. How many people ever want to do that? Well it turns out that the more I thought about how quirky a suggestion it was the more often I began noticing opportunities where I'd like to do the very thing. So I caved and wrote Play In Album Context.

If you select a track and then launch the script a new playlist will be created from the tracks of that track's album (actually, tracks that have the same Artist, Album, and Disc Number tags—whether that results in gathering the correct tracks for the album depends on how well you've tagged your tracks) and the selected track will begin playing from its album position in the playlist.

If a track is playing and the script is launched, the album playlist is created as described above, and the current track will continue playing from its album position in the new playlist. The trick of the script is to temporarily set the playing track's bookmarkable property, pause iTunes, and then immediately play the same track in the playlist; the track picks up playing from the bookmark set when the track was paused. There is a slight stutter when this transfer occurs, but if the goal is to hear the succeeding tracks in album context, it's probably a small inconvenience to bear.

September 10 2011 - 9:49 am

Key Code Searching

Here's a snippet I've been using for awhile which I just got around to posting on the key codes page. I keep my iTunes Column Browser set with Artists and Albums listed On Left. Whenever I'm looking for a particular album I run this script to select the Music library and put focus on the Search box:

tell application "iTunes"
	-- select the Music library
	reveal (some playlist whose special kind is Music)
end tell
tell application "System Events"
	-- bring focus to Search box - Command-Option-F
	key code 3 using {command down, option down}
end tell

I've given it a keyboard shortcut of Command-Option-S.

More information on AppleScripting iTunes with key codes and keystrokes is here.

August 14 2011 - 1:01 pm

UPDATED: Quick Convert 3.0

Quick Convert v3.0 will convert all or just the selected tracks of the selected Playlist using your choice of available iTunes encoders, restoring your Preferences-set encoder afterwards.

Works with importing selected CD tracks, too.

  • Choose to delete and/or Trash the original tracks and/or files
  • Copy all converted/imported tracks to a new playlist
  • Optionally save AAC encoded tracks as M4B "bookmarkable" and re-add the converted files to the Books library

This latest version consolidates all options into a single window and displays progress during track processing.

Quick Convert v3.0 is for OS X 10.6 or 10.7 only. Previous universal version for PowerPC machines available at the entry page.

May 29 2011 - 6:45 pm

UPDATED: Change Hidden iTunes Preferences v2.5

Found a bug in Change Hidden iTunes Preferences that affected how the "Maintain Grid View for Search Results" pref was applied. Current versions of iTunes regarded the setting somewhat ambiguously so I fixed that. Additionally, to be clearer, that pref is now labeled "Grid View Search results switch to List View", since by default, iTunes maintains whatever view is in use for search.

February 26 2011 - 11:49 am

Skip and Pretend We Played This Redux

A popular item on the Missing Menu Commands page is Skip and Pretend We Played This. If a song is playing that you don't really want to hear, you'd launch this script to increase its play count by 1 (since it would not be increased until the track actually finished playing), set the last played date to the current date and time (ditto), and play the next track. I use it in a live-updating Smart Playlist that, among other criteria, uses the last played date to only list songs not played in the past few weeks. This keeps any track I don't want to hear from re-appearing for another few weeks. Ideally launched via shortcut, and so on.

But ANYway.

Correspondent Dirk Scharff noted that "if used in the first 2-20 seconds of the song the skip counter is increased too and that's somewhat undesirable as this wouldn't happen if I played that song." I don't pay much attention to skips at my house, but he has a point. So Dirk submitted a mod to the script which I have incorporated below:


February 25 2011 - 9:25 am

NEW: A Space Between v1.0

iTunes has had the Crossfade feature for a while, whereby consecutive songs will overlap for a few seconds at end-to-beginning. But what if you want the opposite effect: a set amount of silence between each song? But you can't set a negative Crossfade. A Space Between is an AppleScript applet that will wait a user-set number of seconds between plays of consecutive tracks in a playlist. Just select a playlist, or a track in a playlist, launch the applet, and enter a number of seconds.

The tracks will play, pausing for the entered number of seconds between each track.

Site contents © 2001 - 2020 (that's right: 2001) Doug Adams and weblished by Doug Adams. Contact support AT dougscripts DOT com. About.
All rights reserved. Privacy.
AppleScript, iTunes, iPod, iPad, and iPhone are registered trademarks of Apple Inc. This site has no direct affiliation with Apple, Inc.
The one who says "it cannot be done" should not interrupt the one doing it.