Archive for the ‘Controlling iTunes’ Category

October 6 '14 - 8:01 am
UPDATED: Needle Drop v5.0

Needle Drop v5.0 will play each track in the selected iTunes playlist for a set time interval optionally starting at a set number of seconds into each track, beginning with the selected track. Handy for ’scoping playlists.

The latest version adds support for OS X 10.10 Yosemite and iTunes 12 and has other minor tweaks.

More information and download is here.

August 16 '13 - 9:34 am
Toggle Stereo/Mono Audio Output

Correspondent Simon Crosbie has set up an amp and pair of speakers in his workshop which is connected to an Airport Express. Unfortunately, the speakers are some distance apart, so that he may be near one speaker or another at any time, and will only hear that channel’s output. Simon wanted to know if there’s a way to toggle between stereo and mono output so he can hear more than just half of a stereo recording.

Yes, there is a way. Go to System Preferences > Accessibility. Choose “Audio” in the left-hand list and in the panel that appears click the checkbox next to “Play stereo audio as mono”.

Goodnight everybody!

Wait a minute. I almost forgot I wrote this script to do it:

tell application “System Preferences”

reveal anchor “Hearing” of pane id “com.apple.preference.universalaccess”

end tell

tell application “System Events”

tell application process “System Preferences”

set frontmost to true

tell window “Accessibility”

##–> pre 10.9 set monoStereoCheckbox to checkbox 2 of group 1

set monoStereoCheckbox to checkbox “Play stereo audio as mono”

if (get value of monoStereoCheckbox) as boolean is true then

set ddMessage to “Switch to STEREO output?”

else

set ddMessage to “Switch to MONO output?”

end if

if button returned of (display dialog ddMessage buttons {”No”, “Yes”} default button 2) is “Yes” then

tell monoStereoCheckbox to click

end if

end tell

end tell

end tell

if application “System Preferences” is running then

tell application “System Preferences” to quit

end if

[UPDATE November 13, 2013: The original script has been updated for Mavericks. Note the commented line for pre-10.9 systems and the line that follows it. Set the monoStereoCheckbox variable using one or the other depending on the OS.]

[UPDATE October 17, 2014: Another change for compatibility with Yosemite. The line "set frontmost to true" is inserted right after the first tell application process "System Preferences" line near the beginning.]

I would save this script in the system wide Scripts menu (install it in ~/Library/Scripts/). Because the script uses (gulp) GUI scripting you must make sure that “Enable access for assitive devices” is checked in the Accessibility System Preferences panel.

Smarties among you can figure out how to switch mono/stereo when using AppleScript to change AirPlay speakers.

And bear in mind that while the script works with the current OS (and probably an OS that may be released this Fall), Apple may change the layout of the System Preferences panels in a future update, in which case the GUI scripting will have to be updated.

November 30 '12 - 9:54 am
UPDATED: Play Random Album v3.1

Play Random Album scans your library, creates a playlist of a complete single album choosen at random and begins playback of the playlist created. Works great when assigned a keyboard shortcut.

This version works around a problem with iTunes 11 whereby after starting to play the first track of the new playlist no additional tracks appear in the MiniPlayer/Up Next and only the first track ever plays. The script now waits until the playlist is completely assembled before starting to play it.

June 6 '12 - 10:52 am
UPDATED: Change Hidden iTunes Preferences v3.0

Thanks to a couple of recent posts at Mac OS X Hints and Cult of Mac, Change Hidden iTunes Preferences saw a lot of downloads in the past week or two. Unfortunately, I hadn’t had time until today to give it an update. An older preference, “Show buttons horizontally”, is no longer applicable and a new preference, “Disable ‘elastic’ scrolling behavior”, applicable in Lion, needed to be added. These changes are in the latest version of Change Hidden iTunes Preferences.

Additionally, this version is written as a Cocoa-AppleScript applet and can only be run on OS X 10.6 or better.

February 27 '12 - 10:26 am
Custom Playlist Column Views, Sorta

Here’s something I’m often asked which Correspondent Rob Falk put succinctly: “Is there a way to clone a playlist view…other than the Library [using Assimilate View Options]? I frequently need to create a playlist that has a specific set of columns, that are not the same as the library, and was looking for a way to automate that.”

There sorta kinda is.

My first thought was to use AppleScript to just duplicate an existing playlist that already had the requisite view settings. (The duplicate command is typically used to copy a track from one playlist to another.) Unfortunately, when iTunes’ AppleScript duplicate command is used to copy a playlist it—bafflingly—creates a new untitled and empty playlist using the properties and views of the Music library playlist. Same as just creating a new playlist. That doesn’t seem right, does it? You’d think—well, I thought anyway—that using duplicate to copy a playlist would behave the same as the playlist contextual menu command “Duplicate” (control-click or right-click on the name of the playlist):

So, my next thought was…just use “Duplicate”. The playlist will be perfectly duplicated, column views and all, and selected in the Source list. Now you’ll have a new playlist named the same as the original with a “1″ at the end and which is populated with the original’s tracks (if it had any). You could create a bunch of playlists with columns set the various ways you like and then “Duplicate” them when you required one. Just rename the new duplicated playlist and delete any tracks. And that part can be automated.

The workflow, then, is to “Duplicate” a playlist manually with the contextual menu command and then run this script right afterwards:

(more…)

January 20 '12 - 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 '11 - 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.

(more…)

October 25 '11 - 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:
(more…)

September 28 '11 - 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 '11 - 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.

Site contents © 2001 - 2014 Doug Adams and weblished by Doug Adams, dougscripts AT mac DOT com. About.
All rights reserved. Legal.
AppleScript, iTunes, iPod, iPad, and iPhone are registered trademarks of Apple Inc.