November 17 2011 - 10:28 am

Some iTunes Match AppleScripting Notes

Cloud-stored tracks that have not been downloaded to iTunes are seen by AppleScript as class shared track until they are downloaded at which point they morph into class file track. This is similar to how an un-downloaded podcast episode morphs from URL track to file track after downloading it. (I have also occasionally experienced a phenomenon whereby, after downloading a cloud track, AppleScript still treats it as a shared track until I restart iTunes. Not sure why that's happening.) A shared track inherits properties from track and does not have a location (file path) property as does file track. Typically, a shared track is the class of track listed in Home Sharing libraries (or old-style shared libraries).

For the most part, the track properties of a cloud track can be manipulated with AppleScript. This is different from how a Home Shared shared track works, the tags and such of which cannot be changed with AppleScript. Presumably, you are the "owner" of cloud tracks and have permission to edit the tags but you are not the owner of Home Shared tracks since they are on a different machine. My understanding is that changes made to a cloud track's tags locally are not automatically updated on other devices on which they appear. A track on another device would need to be deleted and re-downloaded in order for changes to be seen. [Update: I misspoke. Some data, like played counts and ratings, apparently travel to the cloud automatically.]

Several Correspondents have inquired if it is possible to use AppleScript to remove the Apple ID meta-data information that accompanies a downloaded cloud track (which thus "brands" the files with your info). AppleScript is ill-suited for manipulating the meta-data of a file.

There isn't a way to detect the iCloud Status of a track with AppleScript other than checking its class for shared track which may be enough to positively identify the track as an un-downloaded cloud track when detected in a library source. (A Home Shared shared track would be contained by a shared library source.) In any case, there doesn't seem to be a way to detect Uploaded, Matched, Duplicate, or Error status with AppleScript. [Update: or "Exceeded Limit" either.]

In general, a cloud track track object behaves like any other track object, except with commands that only work with other specific classes of track (like refresh or download). A cloud track can be told to play. Same behavior when you manually play—and thus stream—such a track. You can also duplicate (copy) cloud tracks to new or existing playlists with AppleScript. (Best practice: check if a track with the same database ID or persistent ID already exists in the target playlist to avoid copying it two or more times. iTunes now alerts you if this is about to occur if you copy or drag a track manually to a playlist, but AppleScript's duplicate command circumvents this trigger.)

I have not found a way to programmatically download a cloud track. It must be done manually in iTunes.

A cloud track's artwork can be accessed to some degree. AppleScript can determine if it exists, but its data cannot be exported or downloaded. AppleScript can delete artwork of a cloud track but cannot apply artwork data to it. (If artwork is deleted from a cloud track then downloading the cloud track restores the artwork of the local track. This may be contingent on whether or not other tracks in the album have associated artwork.)

There's no way to programmatically delete any type of iTunes Matched track from your iTunes library with AppleScript without eliciting the alert that asks if you want to remove the song and delete from iCloud. And a shared track does not respond to a delete command (error -1708, shared track doesn't understand the delete message). Once it's downloaded and it becomes a file track, however, you can get its location property to rm its file or delete its file to the Trash via Finder scripting. However, this essentially makes the track "dead" and it still can't be removed with AppleScript without the alert popping up. Complete three-way deletion—track from iTunes, file from Finder, track from cloud—can only be done manually in iTunes.

More as it develops.

Site contents © 2001 - 2023 (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.