Waiting for podcasts to download before continueing a script

I have a script that updates my podcasts and then does some more stuff. However, I have ran into one issue. I want the other code to run AFTER the podcasts have been downloaded. Is there any code I can use to make it know when they downloads are finished? I would use a delay, but I’ve heard its processor intensive and it is always the same time, but sometimes downloads take longer. Any help would be awesome!

Thanks

Hi,

try this (it uses GUI scripting to detect the “Downloads” line in the iTunes window)

tell application "iTunes"
	activate
	tell window "iTunes" to set minimized to false
end tell
repeat until check_Downloads_present()
	delay 1
end repeat
repeat while check_Downloads_present()
	delay 5
end repeat

on check_Downloads_present()
	tell application "System Events"
		tell process "iTunes"
			tell rows of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1
				return ((name of static text 1) as Unicode text) contains "Downloads"
			end tell
		end tell
	end tell
end check_Downloads_present

I have a script which does this in a slightly different way. I am not a very experienced Applescript coder, so my script might not be very good. I use the Finder to detect the existence of the Downloads folder as follows (part of my script):

tell application "iTunes"
	updateAllPodcasts
	set dl_exists to false
	set the_folder to "Hard disk:Users:username:Music:iTunes:iTunes Music:Downloads"
	set counter to 0
	repeat until dl_exists is true or counter = 5000
		try
			get the_folder as alias
			set dl_exists to true
		on error
			set dl_exists to false
		end try
		set counter to counter + 1
	end repeat
	set counter to 0
	repeat until dl_exists is false or counter = 15000
		try
			get the_folder as alias
			set dl_exists to true
			delay 1
		on error
			set dl_exists to false
		end try
		set counter to counter + 1
	end repeat
end tell