MacOS – Activating screen saver from AppleScript in Mountain Lion

applescriptmacosscreensaver

I had a script that I used to use to activate my screen saver, and it no longer works in Mountain Lion.

It was a shell script that called an AppleScript script:

#!/bin/bash
osascript /Users/lorin/scripts/lockscreen.scpt

This is what the lockscreen.scpt file looks like:

tell application "ScreenSaverEngine" 
        activate 
end tell

If I bring up lockscreen.scpt in the AppleScript Editor, I get the "Choose Application" dialog popping up asking "Where is ScreenSaverEngine?"

Anybody know the Mountain Lion-y way to activate the screen saver?

Best Answer

That is a nice way of starting a random screen saver. If, however, you'd simply like to start the active screen saver, you can use this in Mountain Lion:

tell application "System Events" 
    start current screen saver
end tell