Screen saver not completely controllable via "defaults write"

#1
I'm trying to control my screensaver via defaults write under Leopard. I can disable the screen saver via this method, but then, it won't re-enable. Here's what I do to disable it:
defaults write ByHost/com.apple.screensaver.xxxxxxxx write idleTime 0​
(where xxxxxxxx is my mac address). This successfully disables the screensaver. I can tell that the command worked, because the screensaver doesn't turn on any more, and when I do the appropriate defaults read, I get the following results:
Code:
% defaults read ByHost/com.apple.screensaver.xxxxxxxx
{
    askForPassword = 0;
    idleTime = 0;
    lastPictureDirectoryChosen = "/Applications/matrix2";
    moduleName = "3D Matrix Code";
    modulePath = "~/Library/Screen Savers/3D Matrix Code.saver";
    tokenRemovalAction = 0;
}
Later I want to turn on the screensaver. I do so via the following command:
defaults write ByHost/com.apple.screensaver.xxxxxxxx write idleTime 180​
I know that the command worked, because I get the following results with an appropriate defaults read:

Code:
% defaults read ByHost/com.apple.screensaver.xxxxxxxx
{
    askForPassword = 0;
    idleTime = 180;
    lastPictureDirectoryChosen = "/Applications/matrix2";
    moduleName = "3D Matrix Code";
    modulePath = "~/Library/Screen Savers/3D Matrix Code.saver";
    tokenRemovalAction = 0;
}
However, despite the correct setting of idleTime, the screensaver never turns on again, and I have to go to System Preferences and manually change the idle time to Never and then to 3 minutes in order to cause the screensaver to start working again.

I want to control the screensaver programmatically and not via the System Preferences panel, because I'm doing so within an AppleScript. What else do I need to do, in addition to setting idleTime with defaults write, in order to turn the screensaver on again after it was previously turned off?

Thanks in advance.
.​
 
#2
Well, I found an ugly, horrible, hacky work-around for this problem. When restarting the screensaver, I now do this:
Code:
defaults write ByHost/com.apple.screensaver.xxxxxxxx write idleTime 180
/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine &
pid=$!
sleep 0.10
kill ${pid}
(I do this within a shell script)

The short invocation of ScreenSaverEngine is enough to cause the screen saver to re-read its idle time from the plist.

I am not happy with this "solution", though, and I'm thinking that there has got to be a better way to get the screen saver to recognize when the idle time is changed via defaults write from 0 to a positive number.

Any ideas?

Thanks.
.​
 
#3
Bump.

Does anyone have any suggestions about how I can avoid the horrible, ugly hack that I described above, and to get the Screen Saver to recognize the altered idle time after I make the change via defaults write?

Thanks.
.​
 
Top