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.