iTunes - Download all then shutdown computer

I was wondering if anyone might have a script that does the following:

¢ Check iTunes if it’s downloading any files
¢ if the files are downloading do nothing.
¢ if no files are downloading then shutdown the computer.

-files would be any podcasts/movies/etc

Any help would be appreciated.

thanks again.

Hi slashdot,

that sounded interesting to me, so I tried to do it …

The problem is, that only playlists and their contents are scriptable (as it seems to me) and so you can’t communicate with “iTunes Store”, “Shopping Cart” or “Downloads”.

Then I found out, that iTunes will give a warning dialog, if you try to quit while there are uncompleted downloads. And so there is in fact a possibility to script what you want to achive:

global wait_for_iTunes

on run
	set wait_for_iTunes to true
end run

on idle
	if wait_for_iTunes then
			with timeout of 3 seconds
				tell application "iTunes" to quit
			end timeout
			set wait_for_iTunes to false
			return 3
		on error
			-- as long as there are downloads, timeout will fail because iTunes still waits for userinteraction with the dialog ("really quit while downloading?")
			tell application "System Events"
				-- bring iTunes to front and dismiss the dialog. otherwise we can't tell if there are still running downloads the next time we check
				set frontmost of process "iTunes" to true
				keystroke (key code 53) -- the escape key (for "cancel")
			end tell
			return 10 -- check back in 10 seconds
		end try
		-- if there were no downloads, iTunes will have quit without error and wait_for_iTunes will be "false"
		tell application "Finder" to shut down
		quit me
	end if
end idle

I tested the script only with Podcasts and hope it will work with other downloads too…

Hopefully this solves your problem :slight_smile:

thanks creature. Greatly appreciate. I’ll give you some feedback to see how it works.