Is there a script or click menu item to restart or powerdown the mac
By Michael Keeley @Michael_Keeley
I tried using the click menu item macro but what would the apple logo be typed in as?
Thanks!
- Chris Shaw @Chris_Shaw2021-03-14 18:41:00.153Z
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…"], });
- JJonathan Wales @Jonathan_Wales
Awesome!
Thanks
- In reply toChris_Shaw⬆:RRichey McCourt @Richey_McCourt
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.1Chris Shaw @Chris_Shaw2022-05-23 19:45:18.056Z
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//- RRichey McCourt @Richey_McCourt
Perfect! Thanks Chris!
- MIn reply toMichael_Keeley⬆:Michael Keeley @Michael_Keeley
That’s great! Thanks so much!