A script to se screen saver preferences, ie: which screen saver to use

Hi all

I am a newbie at Apple scripting.
I tried to see if there was a unix command but have come up empty.
I would like to know if there is a script to tell your mac which screen saver to use.
My company has implemented a standard screen saver. I can send the file to each user using ARD but I am not sure how to set each user without going machine by machine.
I see scipts that do everything but what i need.

Any Help would be appreciated
Thanks
Virginia

There’s a preference file for each user that stores their screen saver preference. It’s located in…

~/Library/Preferences/ByHost/com.apple.screensaver.xxxxxxxxxxx.plist

There’s some number for the “xxxxxxxxxxx” part, it’s different for each user and I’m not sure where it comes from. I’m sure somebody here knows though.

I have 2 ideas about this…

  1. You can just write that plist file to each user using ARD just like you are going to add the screen saver to each machine. You can set up your machine with the screen saver, that will give you a plist file with the proper settings. Then you just need to add the “xxx” part for each user and copy it to each machine.

or 2. You can figure out the “defaults write” command to add the preference to the plist file and use that to add it for each computer.

Hi regulus,

The “xxxxxxxxxxx” part is the primary MAC-address of the computer, you can get it with

set myMACaddress to words 2 thru 7 of (do shell script "ifconfig en0 ether | grep -i ether" as string) as string

Very good StefanK! I probably should have recognized the number for what it was myself… I must be a little tired today! :smiley:

Hi Virginia,

this is an example to set a screensaver chosen by a list (located in /System/Library/Screen Savers).
I don’t use ARD, so I have no idea to handle it.

tell application "System Events" to if exists process "System Preferences" then quit application "System Preferences"
set screenSavers to alias ((path to library folder from system domain as Unicode text) & "Screen Savers:")
tell application "Finder" to set savers to name of files of screenSavers whose name ends with ".saver"
set theSaver to choose from list savers
if theSaver is false then return
tell application "Finder" to set thePath to text 1 thru -2 of POSIX path of (file (item 1 of theSaver) of screenSavers as alias)
set theName to text 1 thru -7 of item 1 of theSaver

set myMACaddress to words 2 thru 7 of (do shell script "ifconfig en0 ether | grep -i ether" as string) as string
do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.screensaver." & myMACaddress & " moduleName " & quoted form of theName
do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.screensaver." & myMACaddress & " modulePath " & quoted form of thePath

Of course you can set the screensaver directly,
theName is the name of the saver without the extension .saver
thePath is the POSIX path to the file

tell application "System Events" to if exists process "System Preferences" then quit application "System Preferences"
set thePath to "/Users/myUser/Library/Screen Savers/mySaver.saver"
set theName to "mySaver"
set myMACaddress to words 2 thru 7 of (do shell script "ifconfig en0 ether | grep -i ether" as string) as string
do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.screensaver." & myMACaddress & " moduleName " & quoted form of theName
do shell script "defaults write ~/Library/Preferences/ByHost/com.apple.screensaver." & myMACaddress & " modulePath " & quoted form of thePath

One problem I see with StefanK’s scripts…

I noticed when creating a new user account that the ~/Library/Preferences/ByHost/com.apple.screensaver.xxxxxxxxxxx.plist file does not initially exist i.e. it is not automatically created. I’ve noticed this for many preference files in the past. This preference file isn’t created until a user actually makes a change in the “desktop & screen savers” preference pane. Therefore, this file might not exists for all of the users and therefore if one of StefanK’s scripts are used on one of these machines it won’t work (because there isn’t a preference file to work on).

So my earlier suggestion might be the best solution. That is to create the preference file on one machine, and then use that as a template by duplicating it, changing the duplicate’s name with the mac address of the machine you want to copy it to, and then using ARD to copy it into the right location on each computer.

A simple applescript can help you duplicate the file and change its name to the proper name.