2

Is there a way with an AppleScript or shell script to start the screensaver when you disconnect from a screen sharing session?

For example, I connect via screen sharing from Mac A to Mac B. When I disconnect my remote screen sharing session I would like to start the screen saver on Mac B thus locking that screen.

1
  • You can start a screensaver with open -a ScreenSaverEngine, but I don't know how to run it automatically when you disconnect from a screen sharing session.
    – Lri
    Oct 14, 2013 at 19:40

1 Answer 1

1

ScreenSharing will post several distributed notifications during a screen sharing session. It is necessary to listen to those notifications to be able to act on them. I attempted to find a command line executable that is included with Mac OS X to perform this function. Although there is a notifyutil executable in Mac OS X, it does not act as an observer to the NSDistributedNotificationCenter. I also looked at the terminal-notifier project, but it appears to only post User (GUI) notifications.

I've created a Foundation executable that can be run in the background to detect when a screensharing session ends (and start the ScreenSaverEngine as mentioned by @Lauri Ranta above). I have posted the source for this executable on GitHub. You can use Xcode to build the project, and then launch the software as you'd like (via a launchd job?)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .