Using cron to shutdown machine while at login window

I have a problem with my “Energy Saver” prefs in that the machine won’t shutdown at the scheduled time, so I wrote a script:

on awake from nib theObject
	tell application "System Events"
		shut down
	end tell
end awake from nib

but when the machine is sitting at the login window the script launches from cron but just sits there and won’t shutdown, so then I tried to at a “killall loginwindow” to the script to see if that was the hangup, but that only recycles the loginwindow with no shutdown.

Can someone please tell me how to execute a shutdown if a machine is at the login window?


what user is the cron running as ?


I’ve tried it as many users including


you should just use the unix command for it from the cron

shutdown -h now

and must be run as root, i havent tested it but it should work.


I tried that and it works (I’m using Cronnix) if I test it with the “RUN NOW” button, but if I set it to run at a certain time and then log out to the login screen the command does not execute.

Any ideas?


BTW… Yes it’s set in root.

i just tried it using /etc/crontab and it didn’t shutdown the system (same problem your having), which is strange. maybe it runs of launchd or something ?

That’s a good possibility. I’ll try and figure it out. I’ll post if I do.


Do you know how the “Shut Down” button is utilized on the login window?


no, but we cant get a unix command to run so something tells me that the cron is ignored.(which seems crazy)

i think you may need to use a plist file out lined in here
man launchd.plist

Sorry, I forgot to mention that this problem is on my Panther machines.


good news i got it to work

i created this file and saved it /Library/LaunchDaemons/com.custom.shutdown.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">
<plist version="1.0">

and they typed in
sudo launchctl load /Library/LaunchDaemons/com.custom.shutdown.plist

and it will be done (change the hour and min digit to suit yourself)

Thanks I’ll use that for my Tiger machines. I wish it were that easy on Panther.



Do you know how to get a script to push a button on screen?.. say the shutdown button in the login window?


i have no idea about the login window buttons.