Skip to content

Instantly share code, notes, and snippets.

@atifazad
Last active April 24, 2024 01:01
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atifazad/6afd3cbedb8819dd7ed7be92dec2dc0d to your computer and use it in GitHub Desktop.
Save atifazad/6afd3cbedb8819dd7ed7be92dec2dc0d to your computer and use it in GitHub Desktop.
osascript commands to shutdown, restart, sleep and logout mac

Shut down without showing a confirmation dialog:

osascript -e 'tell app "System Events" to shut down'

Shut down after showing a confirmation dialog:

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

Restart without showing a confirmation dialog:

osascript -e 'tell app "System Events" to restart'

Restart after showing a confirmation dialog:

osascript -e 'tell app "loginwindow" to «event aevtrrst»'

Log out without showing a confirmation dialog:

osascript -e 'tell app "System Events" to  «event aevtrlgo»'

Log out after showing a confirmation dialog:

osascript -e 'tell app "System Events" to log out'

Go to sleep (pmset):

pmset sleepnow

Go to sleep (AppleScript):

osascript -e 'tell app "System Events" to sleep'

Put displays to sleep (10.9 and later):

pmset displaysleepnow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment