Archive for October, 2012

October 22 '12 - 12:16 pm
Find Truncated Tracks

So there’s this problem with iTunes Match whereby a downloaded file is unable to be played all the way through. My friend Kirk McElhearn describes the problem in great detail here. Essentially, the iTunes Match file is downloaded but some kind of corruption in the file prevents audio data from being read/played all the way through to the end even though all the data is very likely extant. If a truncated track and associated file are deleted it can be re-downloaded intact successfully. But it is difficult to hunt these tracks down since the reported duration, start, finish, size and time values of the tracks are correct and there is otherwise nothing detectably unusual about them.

The only way to discover if a track is truncated is to play it and hear it end abruptly. Since it appears that less than half the audio data of these tracks is playable, I found that by starting to play the track after positioning the cursor very close to the end of the track in the iTunes LED window the next track would play immediately if the clicked-on track was truncated.

So I’ve written a script, Find Truncated Tracks, that automates this process for a playlist of tracks and copies the varmints to a discrete playlist for later recycling. Find Truncated Tracks will go through the tracks in the current playlist starting with a single selected track. It will position the play head at ten seconds from the end of the track. Then, it will play the track and immediately check the player position. If the track is truncated, the player position will be the last playable second of the track which will be much sooner than the ten-seconds-from-the-end play position at which the track was just set to start. Thus detected, this truncated track will be copied to a new playlist named “_Truncated Tracks”. And so on for each track in the playlist from the selected starting track.

Unfortunately, it’s not terrifically fast. Each track must be played in real time so that the script can detect if it can play all the way through. Fortunately, a track only needs to play for a fraction of a second to get its current player position. But still, the script’s not going to finish up instantaneously. Average running times at my house were about three minutes per thousand tracks.

Play counts are not affected.

You may run into a dialog that will popup for unauthorized purchased tracks (if you have any of those). AppleScript can’t prevent this, so that may put the kibosh on unattended use. Otherwise, just let it run and go out for a sandwich.

October 9 '12 - 12:27 pm
I Hate GUI Scripting Except When I Don’t

Sometimes the only way to script anything that isn’t explicitly in an app’s scripting definition is to use GUI Scripting. I always look for some other way before resorting to GUI Scripting since it can get pretty oogly and is dependent on the app’s GUI; if the developer changes the GUI then the script can be rendered useless. With that said, a Correspondent writes:

“In iTunes, I utilize checkboxes to determine what songs are synced to my iPhone. I do not utilize playlists because I want to keep complete playlists in my iTunes library while still syncing them to my iPhone, minus any unchecked songs. The problem is that iTunes will not play unchecked songs continuously, which annoys me. I recently discovered, however, a preference called “Show list checkboxes”. Unchecking this will hide the checkboxes column and allow me to play my songs uninterrupted, but when I want to sync my iPhone I have to show the checkboxes again so that it won’t try to sync my entire huge library.

I was wondering if there was any way that you could create a script that toggles this preference on & off, in order to reduce the number of clicks required to switch between playing all of my music and syncing my iPhone. This would be much appreciated.”

There’s no explicit command to toggle this behavior, but this bit of GUI Scripting’ll do it:

tell application "iTunes" to activate

tell application "System Events"

tell process "iTunes"

click menu item 3 of menu 2 of menu bar 1

click button 1 of UI element 5 of window 1

click UI element 25 of group 1 of window 1

click UI element 1 of window 1

end tell

end tell

You must have set up GUI Scripting using the instructions found here. And be warned that if the Preferences panel of iTunes changes in the future this script may no longer work.

As usual, works best with a keyboard shortcut.

October 9 '12 - 10:43 am
Emulate Drag Playlist Folder to Make New Playlist

You can use the “Duplicate” option in a playlist’s contextual menu to make an exact copy of the selected playlist. This works for regular and Smart playlists. You can also select a playlist and drag it in the Playlists section of the Source list to duplicate it as a regular playlist. Using this method will duplicate any kind of playlist as a regular playlist. This is especially useful for making a playlist from a Playlist Folder, which does not have “Duplicate” in its contextual menu.

But you may find it easier to run a script on a selected playlist to duplicate it, especially if you aren’t wild about the drag-and-duplicate method which can be slippery. The script below will duplicate any selected playlist as a regular playlist. The new playlist will have the same name as the selected playlist, but you can edit this to include ” copy” or something if you wish:

tell application "iTunes"

set selectedPlaylist to view of front window

set newPlaylist to (make new playlist with properties {name:(get name of selectedPlaylist)})

duplicate tracks of selectedPlaylist to newPlaylist

reveal newPlaylist

end tell

(The last command to reveal selects the new playlist; you may not want this.) Name it whatever you like and Save it as a compiled script in ~Library/iTunes/Scripts/. I’ve found this very handy for making playlists from Playlist Folders that contain several playlists (or sub-Playlist Folders of playlists). Works great with a keyboard shortcut.

October 4 '12 - 4:43 pm
UPDATED: Playlist Manager v1.1

Playlist Manager v1.1 can perform common useful tasks on a multiple selection of playlists: rename (add text, remove text, search and replace text), toggle repeat and shuffle, duplicate, delete, export, merge.

This latest version fixes a problem with renaming playlists that are contained in Playlist Folders and now allows “blank” to be used as the replace text in the Search and Replace tool.

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.