Shutdown computer after download

Hey all,
I’m trying to write a script that will shutdown my computer after a BitTorrent download is finished. That way I can download things overnight and I don’t have to let my computer idle for the 5 hours between the time the download finishes and I wake up. I have the followring shutdown script that works perfectly:

display dialog "Number of minutes until Shutdown?" default answer "60"

set timer to text returned of the result

do shell script "sodo shutdown -h +" & timer & " timed shutdown "

do shell script "sodo -k"

The BitTorrent client that i use is BitTorrent V 4.4.1, and I have no idea how to figure out if the file is finished downloading, any ideas ?


Model: MacBook Pro
AppleScript: AppleScript 1.10.4
Browser: Safari 417.8
Operating System: Mac OS X (10.4)

I find it hard to believe that you’ve actually tested that script. The shell command is “sudo”, not “sodo”, and it requires administrator privileges and a password to run the first time. You don’t say what version of OS X you’re using either, and the commands have changed as OS X evolved.

To watch a file grow, you check it’s size. This is how it’s done in OS X 10.4.6

set myFile to (choose file) as alias -- a dialog asks for the file that's loading
set firstSize to size of (info for myFile) --get initial size of the file
delay 3 --wait 3 seconds
set newSize to size of (info for myFile) --get a newer size, bigger
repeat while newSize ≠ firstSize --if they don't equal, loop until they do
	set firstSize to newSize --new base size
	delay 3 --wait three seconds
	set newSize to size of (info for myFile) --get a newer size
end repeat --once the sizes match, the download is done

At this point you can shut down or sleep.

Yeah i just realised the sodo, transcription error haha. You have an interesting concept, i’ll try it out.

I realize this is kind of an old thread but for future readers here’s kind of a hackish way to do it with UI scripting. You have to have “Access For Assistive Devices” turned on in System Prefs/Universal Access for UI scripting to work.

activate application “Finder”
tell application “System Events”
tell process “Finder”
click menu item “Shut Down” of menu 1 of menu bar item “Apple” of menu bar 1
end tell
end tell

This should do it with out requiring a password.

Hi PolarBear,

there is a shorter way:

tell application "System Events" to shut down

Just use the example Applescript gives you and edit where it displays dialog to tell you the time is up, just put what Stefan put above. Now you can set a time say, 5 hours and then your computer will shut down.

I used it to make a small app to countdown untill iTunes shuts off and then my computer shuts off. (I listen to iTunes when I got o bed)