AppleScript to Shutdown

This is an extension to the closed thread at AppleScript to Shutdown

In the last answer an AppleScript was posted by Noaks to recursively quit all open applications before a shutdown.


tell application "System Events"
set ProcNm_ to name of every application process whose visible is true
repeat with i_ from 1 to count items of ProcNm_
set TarProc_ to item i_ of ProcNm_
try
tell application TarProc_ to quit
end try
end repeat
shut down
end tell


The code was not working for me in Mac OS X Sierra.

Posted on Jan 31, 2018 9:59 AM

Reply

Similar questions

1 reply

Jan 31, 2018 10:03 AM in response to acsrarmin

I made this working by changing the execution of the loop to quit open programs to be executed outside of the Systems Event context like this:


tell application "System Events"
set ProcNm_ to name of every application process whose visible is true
end tell
repeat with i_ from 1 to count items of ProcNm_
set TarProc_ to item i_ of ProcNm_
try
tell application TarProc_ to quit -- you can add "without saving" if you need no action!
end try
end repeat
tell application "System Events"
   shut down

end tell

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

AppleScript to Shutdown

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.