Slow applescript response

I wrote an applescript to Burn an audio CD in iTunes. It works perfectly, but in one part the script slows up and I can’t figure out why.
after the click button “Burn Disc” of window “iTunes” step I have to put in a delay or it won’t click the radio button correctly. Even without the delay script step the script is very slow between opening the burn window, clicking the radio button, and clicking the “burn” button.

any idea’s

thank you

Kevin

tell application “iTunes”
activate
set view of front browser window to user playlist pList
tell application “System Events”
try
tell process “iTunes”
click button “Burn Disc” of window “iTunes”
delay 1
if typeCD is “Data” then
click radio button “Data CD or DVD” of window “Burn Settings”
else
click radio button “Audio CD” of window “Burn Settings”
end if
click button “Burn” of window “Burn Settings”
end tell
on error
set addenda to “Error with your Superdrive. Your CD has not been burned. I will now delete the track from iTunes and return to your database. The voice note in your database has not been touched.”
set user_cancel to “Super Drive Error”
return {addenda, user_cancel}
end try
end tell

Model: Intel iMac
Browser: Safari 525.27.1
Operating System: Mac OS X (10.4)

Hi,

in GUI scripts it’s always preferable to wait for certain UI elements instead of unreliable fixed delays


.
click button "Burn Disc" of window "iTunes"
	repeat until exists window "Burn Settings"
		delay 0.5
	end repeat
	if typeCD is "Data" then
.

I thought the rule was: In GUI scripts it’s better to not use GUI scripts. :D:P

I would have preferred to write an applescript that directly controlled the Burn process, but I don’t see a way to do that without GUI.

My full burn subroutine is below. I will incorporate the repeat loop suggestion, but I suspect it will not solve the long lag time before the Burn button is clicked.

If you have a suggestion of how to script this without the GUI I would love to see it.

thanks to all for the help

on Burn_the_CD(pList, gwarn, typeCD)

activate me
if gwarn = 1 then
	display dialog "Do not use this computer while iTunes is Burning the CD." & return & return & "Do not Press any buttons in iTunes. It will be done for you." & return & "Insert a blank CD when iTunes asks for it." & return & return & "If iTunes gives an error message or you feel something is wrong, then quit iTunes to reset." buttons {"I understand"} default button 1 with icon 2 giving up after 5
else
	display dialog "Do not use this computer while iTunes is Burning the CD." & return & return & "Do not Press any buttons in iTunes. It will be done for you." & return & "Insert a blank CD when iTunes asks for it." & return & return & "If iTunes gives an error message or you feel something is wrong, then quit iTunes to reset." buttons {"I understand"} default button 1 with icon 2
end if
tell application "iTunes"
	activate
	set view of front browser window to user playlist pList
	tell application "System Events"
		try
			tell process "iTunes"
				click button "Burn Disc" of window "iTunes"
				delay 1
				if typeCD is "Data" then
					click radio button "Data CD or DVD" of window "Burn Settings"
				else
					click radio button "Audio CD" of window "Burn Settings"
				end if
				click button "Burn" of window "Burn Settings"
			end tell
		on error
			set addenda to "Error with your Superdrive. Your CD has not been burned. I will now delete the track from iTunes and return to your database. The voice note in your database has not been touched."
			set user_cancel to "Super Drive Error"
			return {addenda, user_cancel}
		end try
	end tell
	-- set m to be a counter to give up after 10 minutes
	set m to 0
	repeat until m = 600
		--is itunes running or did user quit it
		if (my test_process("iTunes")) then
			try
				set Is_CD_Burn_Complete to (kind of container of view of front browser window is audio CD or kind of container of view of front browser window is MP3 CD)
			on error
				set addenda to "iTunes reported an error or you quit iTunes. Your CD may be corrupted. I will now delete the track from iTunes and return to your database. The voice note in your database has not been touched."
				set user_cancel to "iTunes error discard CD"
				return {addenda, user_cancel}
				exit repeat
			end try
			
			if (Is_CD_Burn_Complete) then
				delay 2
				try
					tell application "System Events"
						tell process "iTunes"
							click the menu item "Eject Disc" of the menu "Controls" of menu bar 1
						end tell
					end tell
				on error
					set addenda to "Your CD was not burned because of an unexpected error. I will now delete the track from iTunes and return to your database. The voice note in your database has not been touched."
					set user_cancel to "CD Burn error"
					return {addenda, user_cancel}
				end try
				set addenda to "Disc burn successful. I will now delete the track from iTunes and return to your database. The voice note in your database has not been touched."
				set user_cancel to "CD Burn successful"
				return {addenda, user_cancel}
				exit repeat
			else
				delay 1
				set m to (m + 1)
			end if
		else
			set addenda to "iTunes has quit. I will now delete the track from iTunes and return to your database. The voice note in your database has not been touched."
			set user_cancel to "CD Burn canceled by user"
			return {addenda, user_cancel}
			exit repeat
		end if
	end repeat
	if m = 600 then
		set addenda to "Your CD was not burned because iTunes stopped responding. I will now delete the track from iTunes and return your database. The voice note in your database has not been touched."
		set user_cancel to "iTunes timed out"
		return {addenda, user_cancel}
	end if
	
end tell

end Burn_the_CD

Model: Intel iMac
Browser: Safari 525.27.1
Operating System: Mac OS X (10.4)