Thursday, June 9, 2005

AppleScript frustrations (cont.)

Since the code that I wanted to write to determine if a track has been added to iTunes was not working, this is the code that I have found that works the best.  It seems that the only way to determine if a track is already added to iTunes is to add it, and then if iTunes throws an exception, then the track was already added.

tell application "iTunes"

with timeout of 300 seconds

The easiest way to figure out if this track is already in the library is to

-- add it.  If the number of tracks increases, then the track was not in there


-- Ideally this would be able to call something like:

(exists (get some track of library playlist 1 whose location is theFile))

set this_track to {}

set fAddedFile to false

set gotException to false


set initialCount to get count of every file track of library playlist 1

set this_track to (add theFile)

set countAfter to get count of every file track of library playlist 1

if countAfter > initialCount then

set fAddedFile to true

end if

on error

This is where we catch the error if the track has already been added to the library:

end try

end timeout

end tell

It is pretty bad that iTune's AppleScript dictionary is not better.

Technorati Tags:

No comments:

Post a Comment

Unlocking Raspberry Pi Potential: Navigating Network Booting Challenges for Enhanced Performance and Reliability

I've set up several Raspberry Pis around our house for various projects, but one recurring challenge is the potential for SD card failur...