Starting/Stopping Screensaver in Mountain Lion

Before Mountain Lion I would start my own “.slideSaver” screensavers using a particular code. After Mountain Lion was introduced it appears they aren’t using the “.slideSaver” style now (due to integration with iPhoto?). The end result is that my scripts simply start the default osx screensaver (apple logo & computer name).

Can anyone help me out as to how to script your own screensaver (or folder of photos if necessary) to start and stop?


Before Mountain Lion I would start a ScreenSaver using the following:

do shell script
“/usr/bin/defaults -currentHost write com.apple.screensaver moduleName '” & screensaver_name & “’ &&/usr/bin/defaults -currentHost write com.apple.screensaver modulePath '” & screensaver_path & “'”

do shell script “/System/Library/Frameworks/Screensaver.framework/Resources/ScreensaverEngine.app/Contents/MacOS/ScreenSaverEngine -background > /dev/null 2>&1 &”

In the above code:
the screensaver_name is “World”
the screensaver_path is “/Volumes/HardDisk/ … /World.slideSaver”


I thank you for your time in advance and I look forward to hearing from you soon.:slight_smile:

If you are doing anything with the screensaver, especially setting prefs, you need to notfy loginwindow that there have been changes and for it to reread the prefs

this is easily done, ussing a bit of compiled C:

#include <CoreFoundation/CoreFoundation.h>
     int main(int argc, char ** argv)
          {
           CFMessagePortRef port = CFMessagePortCreateRemote(NULL, CFSTR("com.apple.loginwindow.notify"));
           CFMessagePortSendRequest(port, 500, 0, 0, 0, 0, 0);
           CFRelease(port);
           return 0;
          }

Source:
http://jesse.hollington.ca/post/3236821801/bluetooth-proximity-detection-on-os-x

then it’s as simple as, in applescript

tell application "ScreenSaverEngine" to activate

I may add. Let’s say you’ve called your little c app “NotifySS”

you’d use it:

/usr/bin/defaults -currentHost write  com.apple.screensaver  moduleName '" & screensaver_name & "' &&/usr/bin/defaults -currentHost write  com.apple.screensaver modulePath '" & screensaver_path & "';/usr/bin/NotifySS"

Hope that helps

Thank you so much for the quick response and the detailed information. You are like a code warrior, and the link showing the source info was also very helpful.

Again, thank you very much.

Hello.

This is just great! :slight_smile:

That little tool, is indeed incredible useful, hopefully one can dig out some information regarding preferences panes, to make something like it, (when it comes to the domains to use, and the port to send a notification on) as it obviates some UI scripting, which may need a password to enable anyway.

I thought I’d add a command line for the compilation, which should enable those not so well versed in developing from the command line on Mac Os X to make it compile, as it needs to be compiled with the CoreFoundation Framework.

 gcc -Wall -o NotifySS NotifySS.c -framework CoreFoundation

For the record: the best screen saver for Os X ever is the Electric Sheep! :slight_smile: