dougscripts.com

October 22 2012 - 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 2012 - 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 2012 - 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 2012 - 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.

September 28 2012 - 12:33 pm

NEW: Playlist Manager

I create, reuse, and recycle playlists frequently and my playlists rarely remain static. A hindrance in my playlist management is the inability to select more than one playlist at a time to, say, delete or rename them. Well, I got around to fixing that with Playlist Manager.

This applet 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.

September 13 2012 - 1:29 pm

UPDATED: Remove n Characters From Front or Back v4.6

Remove n Characters From Front or Back lets you delete a specified number of characters from either the beginning or the ending of the Song Name, Album, Artist, Comments, Composer or Show tag (or their "Sort" siblings) of each selected track. For example, delete the initial digits and the space from "01 First Track", "02 Second Track", and so on.

This updated version caps the maximum number of characters to the length of the shortest text in the selected tags, preventing inadvertent deletion of tag text that may be shorter than the user-set number of characters to remove.

September 12 2012 - 4:01 pm

iTunes 10.7 Released

Apple has released iTunes 10.7—which is not the version unveiled at today's event to be released in October. This modest update contains support for iOS 6 and the new iPod models.

September 11 2012 - 12:26 pm

UPDATED: Search-Replace Tag Text v3.3

Search-Replace Tag Text v3.3 performs a search-and-replace with the text in your choice of tag (Song Name, Show, Artist, Album Artist, Album, Composer, Comments, Genre, or Grouping) in the selected tracks or all the tracks in the selected Playlist. Features case sensitivity and whole word match options and dry run preview.

The latest version sports conventional search fields and has some minor code tweaks.

September 10 2012 - 10:56 am

UPDATED: Drop to Add and Make Playlists v2.2

Drop to Add and Make Playlists v2.2 will accept a single dropped folder containing media files and will add each file to iTunes and then distribute the tracks to playlists named using your choice of the tracks' "Artist - Album" tags or the name(s) of the folder(s) containing the file.

This latest version fixes a problem with trying to process files that cannot be added to iTunes.

August 21 2012 - 7:39 pm

Use TextExpander to Run iTunes AppleScripts

I was inspired by this recent article by Dr. Drang on using TextExpander to insert the URL of Safari's front document wherever you're entering text. There might be some benefits to being able to get current information in iTunes with a TextExpander AppleScript snippet or two. Or, as I describe below, three.

In case you don't know, TextExpander is a typing shortcut tool for the Mac whereby you enter a little abbreviated text and a predefined batch of text is inserted where you're typing. One of its amazing features is its ability to fire AppleScript snippets the same way. TextExpander can't accommodate hulking huge AppleScripts but it does allow for some pretty flexible 'scripting.

Before I get to the AppleScript part, here's how to set up TextExpander:
(more…)

Site contents © 2001 - 2024 (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 be interrupting the one who is doing it.