Delayed reboot after updates

Hello,

I often leave Apple Software Updates running on clients’ computers, and then leave them to run. I need a script that will reboot when finished, so servers will be rebooted and ready to go in the morning. I typically apply updates from .pkg files that are already downloaded, so I don’t use the Apple Software Update interface. This leaves me with several Installer windows with a single default button reading either Close or Reboot.

So far I have this:

set question to display dialog “Are you sure you want to reboot?” buttons {“Yes”, “No”} default button 2
set answer to button returned of question

if answer is equal to “Yes” then
tell application “Finder”
activate
delay 3000
restart
quit
end tell
end if

if answer is equal to “No” then
display dialog “Cancelling reboot” buttons {“OK”} default button 1
end if

I can change the delay line to the number of seconds I need.

The big problem is that Finder issues a shutdown, and Installer App, which has several install boxes open saying either Close or Reboot, says “Mac OS X update requires a reboot to finish” .

So the reboot hangs here. Is there any way to do one of the following:

  • force quit installer first, then issue restart
    OR
  • click default buttons on all windows in Installer first

I could use shutdown -r in a shell script, but I had trouble doing an su to become root.

Thank you for your help!

  • eric

Here is one way to quit out of open applications

set exclude_apps to {"Finder", "System Events", "loginwindow", "AEServer", "SystemUIServer", "osascript", "Dock", "Your app here"}
tell application "System Events" to set the_apps to name of processes whose visible is true
repeat with the_app in the_apps
	if exclude_apps does not contain the_app then
		tell application the_app to activate
		try
			do shell script "/bin/kill `ps ax -w | awk /'" & the_app & "'/ | awk '{print $1}'`"
		end try
	end if
end repeat

Of course you could also do the restart with the shutdown command as you mentioned

do shell script "shutdown -r now" user name "admin name" password "admin password" with administrator privileges

And I’m sure you could also go thru the installer method of hitting the done/okay buttons, but I don’t have the ability to go thru and test that at the moment.