Need to set the screensaver using Applescript — strange bug

I am trying to write a script that will change the screensaver and then immediately start it up. So far I have this:

do shell script "defaults -currentHost write modulePath '~/Library/Screen Savers/Retro.qtz'"
tell application id "" to launch
end try

It works fine at first glance, but after a few minutes, a second screensaver starts up and every other frame displayed on the screen is of the other screensaver! It’s like they’re “competing” for screen time. The amount of time it takes for this to occur is equal to the time set to elapse before the system screensaver starts up. This makes me think that my script is somehow actually creating a second screensaver and not suppressing them systemwide one. Is there any way to make it use the systemwide screensaver? I just want to be able to change the screensaver from Applescript, start it, and have it run smoothly until I stop it! :stuck_out_tongue:



changing a system function by just altering the preference file is a hack, but never a bug :wink:
Consider also the file[MAC Address].plist in ~/Library/Preferences/ByHost/

Doesn’t using the -currentHost argument make it apply to the plists in the ByHost folder? As far as I can tell, the correct file gets changed.

No, -currentHost specifies only the files in ~/Library/Preferences.
The plist files in ~/Library/Preferences/ByHost/ are cache files, which are preferred in some cases
or at least they could affect the function

Okay, so I took your advice and directly accessed the ByHost files. Here’s what I did:

set module_path to "~/Library/Screen Savers/Retro.qtz" --the posix path of the screensaver file
set module_name to "Retro" --the name of the screensaver file without the extension

set myMACaddress to "[the computer's MAC address]"
-- I would use "words 2 thru 7 of (do shell script "ifconfig en0 ether | grep -i ether" as string) as string", except that it said 'can't make words 2 thru 7 of bla bla into type string'

do shell script "defaults write ~/Library/Preferences/ByHost/" & myMACaddress & " moduleName " & quoted form of module_name
do shell script "defaults write ~/Library/Preferences/ByHost/" & myMACaddress & " modulePath " & quoted form of module_path
activate application "ScreenSaverEngine"

I tried this on two Mac Minis. On one of them, it works perfectly. On the other one, the same problems happens: another screensaver opens after a bit and “competes” with the one I started up. By now it looks like this problem is definitely a software conflict of some sort. Can you think of anything off the top of your head that could cause such a thing? If not, any ideas about where I might look to track it down? The problem Mini is a production unit and has a lot of software on it, so I can’t go around and uninstall things willy-nilly. Thanks for all your help!