When my display is asleep, tapping any key on the keyboard awakens it. My cpu never sleeps so an AppleScript poised to run when the screens awaken should be possible. As a relative newbie to AppleScript, however, I don’t know how to set up a script to detect that change, run another script or handler, and then quit the script. Watching for the keyboard would probably miss because the Energy Saver will grab the first key and flush it (I now run the script from a key combo in QuicKeys, but have to tap some other key first or QK doesn’t get it).
Let me simplify this to: how can I tell whether the Energy Saver has put the screen to sleep?
I’m actually using Scenario which will detect and run scripts on Log-in & out, Sleep, Idle, and Hot Key events. The scripts for these are placed in a Scenario Script Launcher Folder in which there are these sub-folders:
HotKey Scripts
Idle End Scripts
Idle Start Scripts
Login Scripts
Logout Scripts
Sleep Scripts
Wake Scripts
Scenario is a Preference Pane. I have SleepWatcher and have used it, but because it’s a command-line tool and it’s operative scripts must be invisible dot scripts, it’s klunky, and hasn’t any gui. Thanks for the suggestion, though.
Display sleep and ScreenSaverEngine are seperate processes, but the ScreenSaverEngine process doesn’t exist when you wake the computer. All you need to do is look for the ScreenSaverEngine process. If you want your script to detect both, just activate ScreenSaverEngine at about the same time your display sleep is set for.
Here’s one scenario where you would need the ScreenSaverEngine to activate. Suppose display sleep is set to one minute and ScreenSaverEngine is set to five minutes. One minute passes and the display goes to sleep. Four minutes later the screen saver comes on unless you tell it right now to activate.
Once, the screen saver comes on. You can start monitoring it by checking for existance.
global last_time
--
on run
set last_time to (current date)
end run
--
on idle
tell application "Finder" to set e to exists process "ScreenSaverEngine"
if e then beep 1
return 2
end idle
My specific problem is that when my Mac “wakes” from a screensaver, the Finder becomes the front-most application. I need another application to be up front when the screen saver goes away.
Something like: on wake tell application “TextWranger” to activate
In that case, you’ll have to master “SleepWatcher”. The link is in StefanK’s post. I’ve used it and it works, but it’s a terminal operation to set it up.
Remember that you can use the unix ioreg to get the idle time. You take the idle time and launch the screen saver. Then the screen saver will detect wake up, And that’s it. You don’t need third party if you know applescript. That’s why we learned AppleScript. To do it on our oiwn.
I don’t know AppleScript well enough to do something this complicated.
I didn’t understand the previous scriptlet that was posted, could someone post a script that would tell an application to come forward when exiting the screensaver?
You might run this script as a stay-open app.
It will trigger at the single event that “ScreenSaverEngine” has quit,
however with some delay.
global SSwasActive
set SSwasActive to false
on idle
tell application "System Events" to set SSActive to exists process "ScreenSaverEngine"
if SSwasActive and not SSActive then tell application "TextEdit" to activate -- as an example
set SSwasActive to SSActive
return 25
end idle