PDA

View Full Version : Shared libraries and Applescript


scottburton11
08-01-2003, 07:29 PM
Not long ago I was faced with the challenge of creating a music library to track our music assets. The most important feature would be multiple users; several people should be able to use it at once. My first thought was "Hmm, iTunes is a music library". However, as friendly as it is, and as extensible it is with Applescript, iTunes simply can't keep track of all the info I need.

Naturally, Filemaker Pro is the best solution; aside from a fully relational database, you get Applescript support! It came together very quickly; scripts in either FMP or iTunes could copy relevant track info (name/artist/album, track ID, etc) to a Filemaker record. Scripts in FMP could be used to play the selected record's track, skip, etc. I even made a second database for playlists, with a join table between, so I could a. keep track of what CD's I've burned, who I've sent them to and why, and b. tell by looking at a track which playlists it's been a part of.

Naturally, the only problem is the location of the iTunes database. Though Filemaker databases can be shared and worked on by multiple users with Filemaker Server, iTunes 3 could not. Some tricky solutions were in order until iTunes 4 was released, at which point everything fell together; both iTunes 4 and FM Server run on the same server machine and can be viewed by multiple users, which is the real goal here.

However, with the change to iTunes 4, some of the AS conventions I've become accustomed to are trickier to do with shared tracks/libraries. For instance, here's my "play" script that resides in Filemaker:

tell application "FileMaker Pro"
set song to cellValue of cell "title" of current record
set songID to cellValue of cell "iTunes DB ID" of current record
end tell

tell application "iTunes"
tell source "Library"
tell playlist "Library"
play (every track whose database ID is songID)
end tell
end tell
end tell

Works fine with local tracks, but things get more complicated with shared tracks. First off, tell source and tell playlist (required, from what I can tell) will no longer be pointing to local sources. Second, when you do this:

tell application "iTunes"
get selection
end tell

while selecting a shared track, you get "shared track ID" instead of "database ID". Hmm.

So does anyone know how to do such operations on shared tracks? I can figure out how to script a switch that decides if it needs to run a script with syntax for local tracks or a script with syntax for shared tracks, but I can't actually figure out the syntax in the first place. If you could get as far as getting a shared track ID from a song, how would you go about playing the song when it's part of a shared library?

Doug Adams
08-02-2003, 07:46 AM
Regrettably, you cannot access shared tracks via AppleScript. This wasn't even possible with "liberal" iTunes 4.0, which allowed internet sharing. AppleScript access to shared tracks might lead to file swapping.

Doug Adams
03-15-2004, 09:39 AM
Well, perhaps it is incorrect to say "you cannot access shared tracks with AppleScript".

Using AppleScript you can access other users on the network (with the correct usernames and passwords), and you can use AppleScript to determine the actual locations of audio files on a remote computer based on track attributes gleaned from shared tracks on a local computer. Indeed, I've written up how to do so in this article (http://www.malcolmadams.com/itunes/itinfo/remcontrol.php), "Access iTunes On A Remote Machine".

I don't suppose it is file sharing in the nefarious sense when you are sharing files on your own closed network.