I have a script which processes certain email messages overnight. Our company has a security requirement that our screensavers auto activate and require password to unlock.
The behavior is not consistent. Sometimes the script will run okay for an entire week. Then, inexplicably, the script will time out the next week. Today was such a day. I ssh’d to the Mac and tried running the script with osascript. Mail.app times out. I tried osascript -e to force Mail to the front and that times out. I tried activating the Finder, but same thing. I tried forcing the frontmost app to false and that didn’t work. I quit the foremost app. After that, when I queried System Events to determine what was now frontmost, it errored.
Next I tried sending commands directly to mail while it was in the background. Those all timed-out as well.
Sent killall ScreenSaverEngine and re-tried all above to no avail.
According to ‘top’ the process status of Mail is sleeping.
If I wake and log into the machine. Then remotely activate the screensaver. The script runs.
Same if I activate the screensaver, and then stop screensaver but not logging in. Script runs.
There’s some weird ‘unconscious state’ the system seems to get stuck in.
The script needs to save attachments from certain messages. I am open to any ideas, crazy or sane.