views:

470

answers:

3

I've written an Applescript that sets various IM clients to away, closes iTunes, and then starts my screensaver.

tell application "Adium"
    go away
end tell

tell application "Skype"
    send command "SET USERSTATUS AWAY" script name "StatusSetter"
end tell

tell application "iTunes"
    if player state is playing then
     pause
    end if
end tell

activate application "ScreenSaverEngine"

It's a password protected screensaver, and I'm trying to (once the screensaver has gone away) do the reverse. Obviously the 'tell' actions for each application are not a problem, but I can't seem to find out how to do these once the screen has been unlocked. I did assume this would be the same as a LoginItem, but it's not.

Any help appreciated!

+3  A: 

Very cool idea – I never thought of doing this. It looks like you might want to use ScriptSaver. This will let you run certain scripts when the screensaver is activated and deactivated. You'll get better coverage this way, and won't need to worry about your script running if you just left your computer on.

Reed Olsen
Ah ha. A better answer than mine.
Josh
I had looked into this, but it's got a small bug in it (that by the look of the comments the developer is aware of) that causes problems on double screens. It's not that it only displays on one screen - I'm running Flurry and it seems to zoom and blur it quite badly on my (one) screen, which is really hard to look at!
James Inman
+1  A: 

One way I can think of, off the top of my head, is to

display dialog "Are you back yet?"

After

activate application "ScreenSaverEngine"

And then, after that, resume everything. That will display a dialog box, behind the screen saver, which will allow you to click a button to resume all your apps.

Josh
Nice, thanks! I think I'll use this at least as a temporary solution, but I'd love a way to be able to do it automatically once I've reactivated the screen.
James Inman
A: 

Ok. After a bit of research, it looks to me, and this could be wrong, that ScreenSaverEngine only runs when the screen saver is running. If this is true, the following code is closer to what you're looking for:

set screenSaverRunning to false

repeat while not screenSaverRunning
    try
     set t to (do shell script "ps awx | grep ScreenSaverEngine | grep -v grep")
     set screenSaverRunning to true
    on error errStr number errNum

    end try
    delay 1
end repeat


--Screen Saver is now running...


repeat while screenSaverRunning
    try
     set t to (do shell script "ps awx | grep ScreenSaverEngine | grep -v grep")
    on error errStr number errNum
     set screenSaverRunning to false
    end try
    delay 1
end repeat

--Screen Saver Stopped / Now at password prompt

The only problem I see is, the ScreenSaverEngine stops running when the password box appears... You could either work around this by constantly checking, or maybe add a delay of long enough for you to type in your password... neither is a great solution...

Josh