scheduled script times out if screen saver security running

I have a backup script that runs at 1am on a few machines that I am having an odd problem with. When the script starts it puts up a dialog box to allow the user to cancel if they happen to still be working on the machine in the middle of the night:


display dialog "Preparing to start a Backup" buttons {"Okay", "NO-NO-NO! Stop!"} default button 1 giving up after 10 with icon note

This works fine except some users insist on activating the screen saver that requires them to type in their password to regain access to the machine as a little inter-office security. In these cases the script launches fine, but the “giving up after 10” bit of the dialog box is somehow ignored and the script hangs with an applescript timeout.

So instead of banning the screen saver security or taking out all of the scripts dialogs, I’m wondering if there is a way to dismiss the screen saver via applescript before any dialogs come up?

By logging in through the Terminal on another machine, I determined the name of the screen saver process (ScreenSaverEngine) and then wrote a test into the begining of the script to determine if the process was running. Then I put all the “display dialog” parts inside an if-then to deep them from being executed if the screen saver variable is true.

I tried just killing the screen saver process, but it was immediately respawned by some system magic, so I went with the idea of turning off the display dialogs.

Andy