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