This isn't the full script - it's just the convert command the causes the error (commenting the convert command makes the script run fine). (The full script then takes the copy and gathers date and time information from the finder)
For any Apple people monitoring this - why doesn't Applescript have mechanism so a script can wait until something is done? With cocoa and delegate messages, this seem like it should easy - although implementing it in the on the applescript language side might be tough. An example for this would be:
tell "iTunes"
set newTrack to (item 1 of convert aTrack)
wait until done converting
-- continue with whatever
end tell
A more general mechanism could use delagate messages to allow scripts to be attached to general application actions - although this rather goes beyond the current purview of Applescript, like this:
on delegate message documentWillClose of application <applicationName>
-- do whatever with the document - while the document is still open - this essentially is a post-routine to the documentWillClose delegate message then
pass delegate message documentWillClose
-- the Applescript could theoretically NOT pass it, I suppose
end delegate message
This would basically be a way to extend application behavior directly using AS. I've wondered if I could use IB to attach scripts aka AppleScript Studio to NIB objects in applications which are NOT Applescript studio built..
This is basically something like 'folder actions on steroids' - it would allow actions to be attached to almost anything - when a track in iTunes is converted, when a document in a application is changed, when a button in a particular application is clicked, etc.
Jim
--- The script:
tell application "iTunes 6.0.4"
activate
-- which tracks
set selectedTracks to selection
-- convert/import selected tracks
with timeout of 3000 seconds
repeat with thisTrack in selectedTracks
try
-- convert the track
set newT to item 1 of (convert thisTrack)
--set newT to thisTrack
on error m number n
if n is -1728 then
activate
my alert_user_and_cancel("User Canceled.")
end if
my alert_user_and_cancel((n as string) & " " & m)
end try
end repeat
end timeout
if frontmost is true then
try
if gave up of (display dialog "Done!" buttons {"Thanks"} ¬
default button 1 with icon 1 giving up after 300 with title my_title) ¬
is true then return
end try
end if
end tell
to alert_user_and_cancel(message)
tell application "iTunes 6.0.4"
display dialog message buttons {"Quit"} cancel button "Quit" default button 1 with icon 0 with title my_title
end tell
end alert_user_and_cancel