2

I'm using the script below to trigger a shutdown but I would like it to give me the normal warning menu with the 60 sec. countdown, I can't figure out the warning menu.

tell application "finder" to shut down    

I don't know what else to put so I get the normal shutdown prompt.

  • idk how to do it exactly from Applescript, but if you set a key command to Shut Down... you could just key press that combo from the script. I'm not sure if you can key command the default Power Button or Ctrl/Eject, but you can if you use Keyboard shortcut prefs to assign a new command. – Tetsujin Mar 30 '16 at 16:08
  • The thing is that I'm using my Amazon Echo to trigger these commands so I can't use a button press. – Kyle Hinkebein Mar 30 '16 at 18:46
  • applescript will 'press the buttons' for you keystroke x using command down etc - see apple.stackexchange.com/questions/36943/… - btw, klanomath is always worth listening to.. he's just tackling it from another angle right now, but equally if not more valid than my attempt. – Tetsujin Mar 30 '16 at 19:25
  • Thanks man, I appreciate the support, I'll definitely check out that link.. – Kyle Hinkebein Mar 30 '16 at 19:51
2

Use the menu item instead:

tell application "Finder" to activate
tell application "System Events"
    tell process "Finder"
        click menu item "Shut Down…" of menu 1 of menu bar 1
    end tell
end tell

If you use another system language than English use the proper shut down command instead. At least in OS X 10.11 you have to allow Script Editor/the resulting app to control your computer in System Preferences -> Security -> Privacy -> Accessibility.


You have to copy the menu item exactly including spaces. E.g. the three dots are not three dots but an ellipsis: alt; -> … (en-US keyboard layout)

  • When I tried this it simply brought Finder to the forefront, it didn't activate the menu bar or anything else.. If I could even get it to automate the shortcut buttons that would be fine. – Kyle Hinkebein Mar 30 '16 at 19:12
  • @KyleHinkebein What's your system version? – klanomath Mar 30 '16 at 19:15
  • Works perfect!!! I retyped it from my laptop to my main system and had those dots wrong.. Thanks!!! Really appreciate it.. – Kyle Hinkebein Mar 30 '16 at 19:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .