Reputation: 1002
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!
Upvotes: 1
Views: 1564
Reputation: 11070
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...
Upvotes: 1
Reputation: 11070
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.
Upvotes: 1
Reputation: 9169
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.
Upvotes: 3