2 Replies Latest reply: Oct 15, 2012 12:09 PM by paulfromhere
paulfromhere Level 1 Level 1 (0 points)

I've been having problems with my iMac not shutting down and finding it alive when I return hours later. So, I've been testing Automator ideas and finally found something that seems to work every time. So, I'm posting it here in case I lose my original and need to install it again. Maybe this'll help someone else too. I couldn't figure out how to export or copy and paste it all, so here are the specific automator steps I used and any changes are mentioned with each. By the way, I am not an apple scripter, but found these scripts by googling and trying different search results, including my own Watch Me Do. If the force quit doesn't help you're problem, then all I can say is sorry, it works here.

 

 

Use Automator to create an App, which I saved as shutdown.app. Then activate it by using Command-Space to activate spotlight and typing the first few letters and return.

 

 

First Automator Action: Set Computer Volume (I use this to reduce the volume to 20% so it won't blare so loud on the next bootup)

 

 

Second Automator Action: Run AppleScript - This will initiate the normal shutdown procedure (paste this into the script):

 

on run {input, parameters}

 

          tell application "System Events"

                    shut down

          end tell

 

          return input

end run

 

 

Third Automator Action: Pause (set to 30 seconds to give some time for the shutdown to prompt you to close any open apps)

 

 

Fourth Automator Action: Quit All Applications (uncheck Ask to save changes)

 

 

Fifth Automator Action: Run AppleScript - This will initiate an "Apple Menu" => "Force Quit" and select any app that didn't get killed by the Quit All Applications routine (paste this into the script):

 

on run {input, parameters}

          -- Click the “Apple” menu.

          delay 1.000000

          set timeoutSeconds to 2.000000

          set uiScript to "click menu bar item \"Apple\" of menu bar 1 of application process \"Finder\""

          my doWithTimeout( uiScript, timeoutSeconds )

 

 

          -- Force Quit…

          delay 5.000000

          set timeoutSeconds to 2.000000

          set uiScript to "click menu item 11 of menu 1 of menu bar item \"Apple\" of menu bar 1 of application process \"Finder\""

          my doWithTimeout( uiScript, timeoutSeconds )

 

 

          -- Click the “Force Quit” button.

          delay 4.167005

          set timeoutSeconds to 2.000000

          set uiScript to "click UI Element \"Force Quit\" of window \"Force Quit Applications\" of application process \"loginwindow\""

          my doWithTimeout( uiScript, timeoutSeconds )

 

 

          -- Click the “Force Quit” button.

          delay 4.898337

          set timeoutSeconds to 2.000000

          set uiScript to "click UI Element \"Force Quit\" of sheet 1 of window \"Force Quit Applications\" of application process \"loginwindow\""

          my doWithTimeout( uiScript, timeoutSeconds )

          return input

end run

 

 

on doWithTimeout(uiScript, timeoutSeconds)

          set endDate to (current date) + timeoutSeconds

          repeat

                    try

                              run script "tell application \"System Events\"

" & uiScript & "

end tell"

                              exit repeat

                    on error errorMessage

                              if ((current date) > endDate) then

                                        error "Can not " & uiScript

                              end if

                    end try

          end repeat

end doWithTimeout

 

 

Sixth Automator Action: Loop (Automatically Stop after 100 times) - This will keep going back through the force kill if any app survived the previous attempt.


iMac, OS X Mountain Lion (10.8.1)
  • 1. Re: How to force my iMac to always shutdown completely
    BDAqua Level 10 Level 10 (116,480 points)

    Great work, thanks!

  • 2. Re: How to force my iMac to always shutdown completely
    paulfromhere Level 1 Level 1 (0 points)

    This script occasionally has an error and ends up not shutting down. It seems the script never goes to the next iteration of the loop. I'm not sure how to fix debug and fix it, so I decided to try bash instead.

     

    I've eliminated the Sixth automator action from the above "shutdown.app" and saved it to "sd.app"

     

    My bash script is an executable file in /Users/paul/Documents/shutdown.sh, and contains:

     

    #!/bin/bash

    while true ; do

    #echo "yes"

    open -n "/Applications/sd.app"

    sleep 60s

    done

     

    My new shutdown.app automator action has

     

    First Automator Action: Run Shell Script (paste this into the script):

     

    exec /Users/paul/Documents/shutdown.sh