Try this:
Code:
on idle
set i to 0
tell application "System Events"
-- Get a count of all the windows belonging to the process
set numberOfWindows to count windows of process "loginwindow"
-- Check each window for a "Shut Down" button....
repeat numberOfWindows times
set i to i + 1
-- ....and shut down if found
if exists button "Shut Down" of window i of process "loginwindow" then
do shell script "shutdown -h now"
end if
end repeat
end tell
-- How often the script checks for the window (in seconds). Change it as you see fit.
return 0.5
end idle
This should be ready to go; copy to Applescript, save it as an application with the "Stay open" option selected, add it to your Login Items.
Very slick, thanks a ton!
One minor nit (and only for completeness in case anyone else wants to do this too) is that the first times I tried this AppleScript gave me some sort of "accesibility error"; forget the exact message, but it was an accessibility error message (or maybe "assisitive"?). After googling it I found the fix was just to go into System Preferences, Accessibility, then select the "Enable access for assistive devices".
This is my first run in with apple script, very intestesting tech... while googling other pieces of the code I discovered that you can also send key presses or key strokes... so we could probably modify the script above so that instead of executing the shell script it simply "activates" that window and then presses the "Enter" key? Since the "Shut Down" button is the highlighted button in that window, focusing / activating the window and then hitting enter will begin the shutdown.
My reason for suggesting this change is that the "shutdown -h now" doesn't work straight-out-of-the-box... I actually had to modify that to "sudo shutdown -h now" instead, and then configure sudo to allow my user account to execute with root priviledges without entering a password...
But thanks very much for the script and getting me 95% there, much appreciated!