Managing Tracks
Get a Track Reference from a File Path
Correspondent Wayne B. recently wondered if there is a way to get a reference to a track in iTunes based on its file path. Well, unfortunately, you can't do something like this:
tell application "iTunes" set trackRef to (get some file track of library playlist 1 whose location is "some/file/path.ext") end tell
That will generate an error. But you can trick iTunes into giving you the track reference by using the add command--if you are certain the file is already in iTunes' database. When you add the file iTunes will check its database for the the corresponding library track for you and if it exists will give up the reference--and it won't re-add it:
set theFile to choose file -- or however you get the file path tell application "iTunes" try set trackRef to (add theFile as alias) tell trackRef log (get name) # and so on... end tell end try end tell![]()
But remember that if the file isn't already in iTunes' database then iTunes will add the file as a matter of course, which may not be what you want. So this trick may work best only when you know a file is currently in your library.
You will not want to use the open command instead of add, because open will compel iTunes to play the file in addition to any add-housekeeping.
Library Benefits
A Correspondent observes that PDFs and digital booklets are no longer lodged in the "Music" library but in the "Books" library. Thus he laments that he is unable to access these books alongside the music tracks while browsing the "Music" library. While book-type tracks and music tracks can reside in the same playlist, yes, they do belong to different libraries. But creating a separate playlist for every album with a PDF or digital booklet doesn't seem very efficient.
I used Change Hidden iTunes Preferences to toggle the visibility of the "Library" library playlist. In the pic below it is listed atop the other library playlists. In the old days, this was the main library playlist and listed everything in the library. Well, it still does. When the "Library" is available, you can use the Column Browser to access an entire Album, which will include any associated booklet (providing the Artist/Album tags correspond correctly):

(The yellow highlight over the booklet is an artistic representation.)
NEW: Report Real Play Time
Correspondent Jamie Shaw sent me a version of a script that calculates the play time of selected tracks or tracks in a playlist when the user-set Start and Stop times are also accounted for. In such cases, the total play time (for a playlist) would be shorter than what is displayed along the bottom of the playlist. I threw in a routine that lets you enter your Crossfade time (not really accessible programatically) and this is also part of the calculation. Report Real Play Time works especially nice when assigned a keyboard shortcut.
NEW: Mark All Episodes As Played
A Correspondent bemoaned the loss of the "Mark as..." contextual menu item when control-clicking a Podcast library subscription title while in List View. I wouldn't have noticed that in a million years. Still, it's an expulsion only slightly more arcane than doing away with my beloved Mute button, so I was sympathetic, and produced Mark All Episodes As Played. While the Podcast library is in List View, select any one (or more) episode(s) of a podcast or its subscription title and run this script to mark every episode of the podcast as Played (or Watched). Works great when assigned a shortcut.
Updated a Handful
Nothing to do with Snow Leopard--what a relief, eh? I've updated seven scripts today:
- Assimilate View Options
- Batch-Delete Playlists
- Block Party!
- Compare Two Playlists
- Export Smart Playlist Criteria
- Move Playlists to Folder
- Selected Playlists To iPod
These seem to be the most popular scripts that are affected by the "none/all" issue introduced in iTunes 8.2. There may be a few others, but I haven't gotten email feedback on those nor have I run across a problem with any other scripts I use regularly. But if you ever get a error like this:
...then let me know.
UPDATED: No Lyrics to Playlist v2.0
No Lyrics to Playlist has been updated to version 2.0. It will search a selected playlist for all tracks in the selected playlist that do not contain lyrics and copy them to a playlist it will create called "No Lyrics". Includes a second script to clear the "No Lyrics" playlist of tracks with lyrics.
This set of scripts was written by Herwin Lans and originally posted about four years ago. Because of changes in iTunes, it required updating and, particularly, the "Clear No Lyrics Playlist" script needed an over-haul.
UPDATED: Gather Up the One-Hits v2.2
Gather Up the One-Hits had a persistent problem for some users whereby only a single track would be copied to the "One Hits" playlist. I believe I have fixed the problem, albeit at a cost of some speed; but it should only take a few seconds rather than a few moments to run.
Genius 4010 Error
This Apple forums discussion post describes an error that many iTunes 8 users are getting:
"iTunes 8.0 gathers data about my music library well enough and sends it to Apple too; but then 10-15 seconds into 'processing' by Apple, iTunes stops and reports that 'Genius results can't be updated right now. An unknown error occurred (4010)'. I thought it might be overloaded servers and tried several more times in the hope of squeezing my request in between those of everyone else; but that didn't work; plus if it were a server issue I'd expect to see postings here from others with the same problems, and I'm not."
Several posters have tried removing dead tracks--tracks whose files cannot be located as designated with the encircled exclamation point--from the library using the script Super Remove Dead Tracks and trying again, and although this didn't work for everybody, several posters did get things working correctly afterwards.
NEW: Add from Amazon MP3 Folder v1.0
Is it just that the Amazon MP3 Downloader application won't automatically add downloads to my iTunes or is this a Windows-only feature? Didn't bother to find out for myself because I decided to have a script do it instead. Add from Amazon MP3 Folder will let you choose the Album folders from your "Amazon MP3" downloads folder and add their files to iTunes. Optionally, if you allow iTunes to "Copy files to iTunes Music folder when adding to library", you can choose to move the original folder(s) and files out of the "Amazon MP3" download folder and to the Trash after they're added to iTunes. Saves a few keystrokes.
It occurred to me to make this a Folder Action--so that files get added as soon as they hit the "Amazon MP3" downloads folder--but Folder Actions can be dicey when working with internet-downloading files. So, you've got to run this from the iTunes Script menu.
I've also included the script "Open Amazon MP3 Folder" that will open your Amazon MP3 downloads folder and make it the frontmost window in the Finder. This script can be run from iTunes' Script menu as well.



