importing new tracks into iTunes
importing new tracks into iTunes
- Subject: importing new tracks into iTunes
- From: Jim Alexander <email@hidden>
- Date: Thu, 15 May 2003 11:32:07 -0400
I've written a script that imports new tracks into iTunes, amongst other
things. This script works just fine if run from Script Editor, but
malfunctions if run from iTunes own script menu. I'm using iTunes 4
under 10.2.5, and haven't tried this script with any earlier version of
iTunes.
The problem is illustrated with this code fragment:
-- thisItem set in a loop out here
set foo to false
try
tell application "iTunes"
activate
set thisTrack to add thisItem to playlist "Library" of source "Library"
set foo to true
-- more stuff
end tell
on error error_message number error_number
if the (error_number is not -128) and (error_number is not -1712) then
set copySuccess to false
tell application "iTunes"
activate
beep
display dialog error_message buttons {"Cancel"} default button 1
end tell
end if
end try
if (foo) then
display dialog "we set foo"
end if
The problem is that the variable foo never gets sets to true, and, more
importantly, all of the code symbolized by the "more stuff" comment
never gets executed. This appears to be caused by an incorrect
optimization iTunes makes: each add to the library returns immediately,
before any actual importing is actually done. A little later, all of the
files are imported at once. That is, since I am doing my testing with
6 files, iTunes says "Copying 1 of 6: ..." rather than the
"Copying 1 of 1: ..." that happens if the script is run from Script
Editor. The problem with this optimization is that everything else in
the tell block is optimized away - my "foo" boolean proves this since
it never gets set to true, and hence the dialog is never displayed.
My "more stuff" code also expects to be able to read and set fields of
thisTrack, so it's possible the optimization is fundamentally incompatible
with what I want to do.
So I think this is clearly a bug, and I will report it as such, but I'm
wondering whether anyone knows any tricks that would work around the
problem by forcing the optimization to not happen? I really need the
tracks to be added in a serial fashion.
(A side note: you'll note that I'm ignoring error -1712 - this is because
if I don't do this, I get an _immediate_ AppleScript timeout from iTunes -
not 30 seconds later - immediate. I don't know if this is a related issue,
but this doesn't occur when the script is run from Script Editor either.)
--
________ Jim Alexander __________________ email@hidden _______
I have yet to see a problem, however complicated, which, when you looked at it
in the right way, did not become still more complicated. -- Poul Anderson
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.