Shutdown Script not working correctly

Hi al,

I have an applescript that actions a shutdown on my mac

Since the recent release of lion and M.lion, when i restart my machine the apple script is launched again which is a pain.

Is there a switch to add onto the end of the below call to shutdown without resume?

tell application "System Events" to shut down


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
 set systemWasShutDownByMe to true
 tell application "System Events" to shut down
end if 

Hey DJ

Im not quite sure what you mean, would i add the property into the shutdown apple script, or have a second applescript?


Replace your code with mine in your script and it should work fine.

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.

It sounds like ML’s automatic state restoration.

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?


I can only guess that there might be a timing issue that affects whether the old state is fully stored before the shutdown.