AppleScript Syntax
Create Shortcut Keys to Select Libraries
There are no shortcut keys to select the Music, Podcast, TV Shows, and other libraries. But you can use AppleScript to create some. Here's how:
Change in Folder Actions
The "on files added" Folder Actions handler in 10.6 now waits for a file to finish "arriving" before being called. Earlier versions would call the handler as soon as the a new file hit the folder. But if the file was very large the handler might fail because the file hadn't completely arrived in the folder. Now, under 10.6, if the file-being-added stays the same size for more than three seconds, it is deemed "done", and the action is called.
The workaround suggested in this Folder Actions and iTunes tip is no longer necessary in Snow Leopard.
Target QuickTime Player by application id
If you've got a script that needs to target QuickTime Player in Snow Leopard you probably really want to target "QuickTime Player 7". Otherwise, if you target "QuickTime Player" the QuickTime Player X app will run and it doesn't have the AppleScript Goodness like QTP7. However, if the script also has to run in Leopard, you have to target "QuickTime Player"--without the "7". But you don't need to write two scripts.
In OS 10.5 and later you can target an app by its application id. I remember seeing that in the AppleScript Release Notes for 10.5 thinking "Hmm. Now how can I use that" and never really thought of anything. Until I needed to access QTP in both 10.5 and 10.6.
This tell block:
tell application id "com.apple.quicktimeplayer" -- do something in QuickTime Player end tell
...will target "QuickTime Player" in OS 10.5 and "QuickTime Player 7" in OS 10.6. The application id is the same for each, so it makes no difference what their names are. And the AppleScript architecture is virtually the same in both operating systems. (Remember that "QuickTime Player 7" is an optional install either during installation or from the "Optional Installs" folder on your installation disc.)
"QuickTime Player X" is a drastically different version of the player app and scripts written for QTP7 will not play well with it. However, it is scriptable to a modest extent. Its application id is "com.apple.QuickTimePlayerX" in case you need to target QTPX specifically.
New track Property
New in iTunes 8.1, the track object has a new release date property.
iTunes 8.1 Released
Apple Released iTunes 8.1 today (v8.0.2 was the previous version). Among the new features are its ability to handle larger libraries more speedily, iTunes Plus (256kbps AAC) importing via CD, and Genius playlists that will scour for video media.
I know of at least one AppleScript enhancement. A track's played date and skipped date properties can now be wiped by setting either to 0 (zero) or missing value. Before, you could never set these properties to anything but a date. While you could set played count and skipped count to 0, the only way to fudge the played or skipped date was to give it a date in the past, like date "January 1, 1970". Now, you can do this:
tell application "iTunes" set sel to selection repeat with aTrack in sel tell aTrack set played date to missing value set played count to 0 -- and/or set skipped date to missing value set skipped count to 0 end tell end repeat end tell
I'll have a look for any other changes.
Library Follow-Up
After playing around with the "show-library-playlist" setting, it looks like you do have to set "hide-library-playlist" also. So, to show the "Library", run these two commands in Terminal one after the other (that is, press Return after entering each):
defaults write com.apple.iTunes show-library-playlist -bool TRUE defaults write com.apple.iTunes hide-library-playlist -bool FALSE
To hide the Library again, run the same commands, but reverse the TRUE/FALSE values.
Show the iTunes Library Old School
I'm not certain if this has been mentioned anywhere--I haven't seen it--but I found the defaults command for displaying the entire iTunes library. Remember when you actually had a large playlist named "Library", before Apple split it up into--what I call--"Master" libraries of "Music", "Movies", "Podcasts", and so on? The "Library" listed everything in your iTunes library. Well, you can get that back using this command in Terminal:
defaults write com.apple.iTunes show-library-playlist -bool TRUE
Quit iTunes before entering the command. When you restart you'll have a new playlist named "Library" at the top of your Source list, above "Music".
If you want to remove the "Library" again, use this command in Terminal:
defaults write com.apple.iTunes show-library-playlist -bool FALSE
There is a second preference called "hide-library-playlist", which I at first thought would have to be set in tandem with the opposite of "show-library-playlist", but this doesn't seem necessary. In fact, you can set one or the other, apparently, and get the desired result; that is setting "show-library-playlist" to TRUE or setting "hide-library-playlist" to FALSE amounts to the same thing. Also, for AppleScript purposes, this playlist can be referenced as library playlist 1; it always could be, but now it is visible.
iTunes 8 and Genius Incompatibilities
As I hinted at yesterday Genius playlists are a new "species" of playlist. Several scripts are affected by their inability to correctly distinguish Genius playlists from other playlist types. I will be working on fixes for them in the coming days. I think, in fact, that you can pretty much attribute any failings of AppleScripts that did work before iTunes 8 to the appearance of one or more Genius playlists. You may want to verify this by shutting Genius off and trying the errant script again. While some AppleScript behaviors have been updated/fixed in iTunes 8, I have not (yet) noticed any new AppleScript features that would otherwise cause scripts to error.
Genius Playlists and AppleScript
As far as AppleScript is concerned, iTunes 8's Genius playlists are user playlists with a special kind of none and a smart value of true, and therefore they are indistinguishable from Smart playlists. I don't know if eventually there will be a special kind value of "Genius", but for now distinguishing a Genius playlist from Smart playlists will not be easy.
Apple Updates the AppleScript Language Guide
After nearly ten years, Apple has finally updated the Introduction to AppleScript Language Guide. Its layout and organization is more consistent with other Apple Developer Connection documentation and is much easier to grok (and much less 1999-internet-looking). It is specifically geared towards AppleScript 2.0 and Mac OS 10.5 or later.