Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.


macrumors newbie
Original poster
Aug 28, 2015
Hi, as I'm sure most readers know, the power button when Sierra(and other OS's) are fully booted, has 3 functions:
Function 1. Press for 1 second, the monitor sleeps
Function 2. Press for 3-4 seconds, the Restart, Sleep, Shutdown dialog box appears
Function 3. Press for 8-9 seconds, a hard shutdown

My question is, can function 1 be changed so that the computer does an orderly shutdown, with no further interaction, instead of putting the monitor to sleep?
Somewhere in the OS there must be programming or an AppleScript, or something that does it.
Does anyone know where in the OS it is located?

Thanks for any help.
Last edited:


macrumors newbie
Original poster
Aug 28, 2015
Hi, the following code nicely utilizes the already built-in code that shows the "Restart, Sleep, Shutdown" dialog box when the power button is pressed for 3-4 seconds. I happened across an almost identical question as mine from canistel from April 2013. Thanks goes to Wondercow for the answer.

on idle
    set i to 0
    tell application "System Events"
        -- Get a count of all the windows belonging to the process
        set numberOfWindows to count windows of process "loginwindow"
        -- Check each window for a "Shut Down" button....
        repeat numberOfWindows times
            set i to i + 1
            -- ....and shut down if found
            if exists button "Shut Down" of window i of process "loginwindow" then
                click button "Shut Down" of window i of process "loginwindow"
            end if
        end repeat
    end tell
    -- How often the script checks for the window (in seconds). Change it as you see fit.
    return 0.5
end idle

This code works perfectly. To use it copy and paste it into Script Editor, save it as an Application, and check the box "Stay open after run handler", copy it into your Applications folder and add it to your Startup items. It will also be necessary to add it to System Preferences > "Security and Privacy" under "Accessibility" and "Privacy", as it needs to control your computer. Then once it's running all you have to do is hold the power button for 4 seconds and the computer will immediately shutdown. Perfect!!
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.