No internet connection
  1. Home
  2. How to

Is there a script or click menu item to restart or powerdown the mac

By Michael Keeley @Michael_Keeley
    2021-03-14 15:01:15.341Z

    I tried using the click menu item macro but what would the apple logo be typed in as?

    Thanks!

    • 6 replies
    1. This will shut down your Mac. It will also click 'OK' when the "Are you sure…" window pops up. Delete the last line if you'd rather confirm manually.

      sf.ui.finder.menuClick({
          menuPath: ["Apple","Shut Down…"],
      });
      
      sf.ui.app('com.apple.loginwindow').windows.whoseTitle.is('').first.buttons.whoseTitle.is('Shut Down').first.elementClick();
      

      This will restart:

      sf.ui.finder.menuClick({
          menuPath: ["Apple","Restart…"],
      });
      
      1. JJonathan Wales @Jonathan_Wales
          2021-03-15 16:30:04.210Z

          Awesome!

          Thanks

          1. In reply toChris_Shaw:
            RRichey McCourt @Richey_McCourt
              2022-05-23 17:15:28.431Z

              Hi Chris,
              For some reason this doesn't work for me?! Tried a few times and states 'Click Button Action requires UIElement'.
              Running OS 12.2.1

              1. try this:

                sf.ui.finder.menuClick({
                    menuPath: ["Apple","Shut Down…"],
                });
                
                sf.ui.app('com.apple.loginwindow').windows.whoseTitle.is('').first.elementWaitFor({waitType:"Appear"})
                
                sf.ui.app('com.apple.loginwindow').windows.whoseTitle.is('').first.getElement('AXDefaultButton').elementClick({
                    onError: "ThrowError",
                });
                

                For restart, replace "Shut Down..." with "Restart..."

                This script will not ask for a confirmation for either shutting down or restarting.
                //CS//

                1. RRichey McCourt @Richey_McCourt
                    2022-05-24 09:12:02.755Z

                    Perfect! Thanks Chris!

              2. M
                In reply toMichael_Keeley:
                Michael Keeley @Michael_Keeley
                  2021-03-15 14:55:04.820Z

                  That’s great! Thanks so much!