7

I know how to shutdown a Mac from Terminal, but is there a way to actually bring up the shutdown dialog you get from Apple → Shut Down…?

grg
  • 192,762
  • 43
  • 337
  • 460
JShoe
  • 4,529
  • 8
  • 26
  • 37

3 Answers3

8

You can send loginwindow the kAEShowShutdownDialog Apple event:

osascript -e 'tell application "loginwindow" to «event aevtrsdn»'

The four letter codes for Apple events are listed in AERegistry.h. See this answer for more information.

Lri
  • 101,672
  • 19
  • 221
  • 272
3

This should work:

Applescript:

-- Open  Shut Down Dialog...
-- Save this text as file named shutdown.scpt
tell application "System Events"
    set uiScript to click menu bar item "Apple" of menu bar 1 of application process "Finder"
    set uiScript to click menu item "Shut Down…" of menu 1 of menu bar item "Apple" of menu bar 1 of application process "Finder"
end tell

You can run it from Terminal like:

osascript shutdown.scpt
nohillside
  • 92,308
  • 39
  • 198
  • 242
l'L'l
  • 8,987
  • 2
  • 27
  • 39
0

You can create an Automator script that you can later run from the command line with "open".

You could "Record" in Automator. I guess that would be the easy way, but there might be other problems. Because when you record, Automator actually records mouse pointer movements…

Martin Marconcini
  • 21,730
  • 1
  • 59
  • 86