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

try

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

Seamless Local Control: Integrating WeatherFlow with Home Assistant Across VLANs

I've been pleased with my Home Assistant setup for some time now. One of my main focuses has been achieving local control. This ensures...