You can add a persistent variable that checks if the latest shutdown was done with this script.
for example:
property systemWasShutDownByMe : false
if systemWasShutDownByMe then
set systemWasShutDownByMe to false
else
set systemWasShutDownByMe to true
tell application "System Events" to shut down
end if
I had a similar problem with a script ending with the option to restart or shut down. The script worked in Lion and before, but in ML it is often (but not always) relaunched after the restart. I have no idea why the commands “tell application “System Events” to shut down” or “tell application “System Events” to restart” started to do this intermittently in ML. Does anybody have an explanation for this behaviour?
As an alternative to DJ’s solution, I simply included the script in a “Run Applescript” action in Automator and saved it as an Automator applet. It runs perfectly this way in ML.
Hi Shane,
Shouldn’t that relaunch the script every time after a restart? In fact I’d say it did relaunch only after about 25% of restarts, as if some background combination triggered the behaviour. I also have to point out that the script was actually saved and run as an AS applet. And then that behaviour stopped as soon as I saved it and run as an Automator applet. To me, it looks like some bug in the ML AS. Any comment?