Desktop Background & ScreenSaver Management

RobertAlviar
New Contributor II

hello JAMF Nation,

may i ask if there is a way for us to manage the desktop background & screensaver for all users who will login to a mac?

company is requesting a specific desktop background (like anouncements or events)
company is requesting a screensaver to be used for displaying company mission and vision.

thanks in advanced! :)

7 REPLIES 7

rderewianko
Valued Contributor II

Not My work but here's what I use for backgrounds, setup as Once per a user per a computer.

#!/usr/bin/python

# https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSWorkspace_Class/Reference/Reference.html
# https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSURL_Class/Reference/Reference.html
# https://developer.apple.com/library/mac/documentation/cocoa/reference/applicationkit/classes/NSScreen_Class/Reference/Reference.html

from AppKit import NSWorkspace, NSScreen
try:
    from AppKit import NSWorkspaceDesktopImageScalingKey
except ImportError:
    NSWorkspaceDesktopImageScalingKey = u'NSWorkspaceDesktopImageScalingKey'
from AppKit import NSImageScaleProportionallyUpOrDown
try:
    from AppKit import NSWorkspaceDesktopImageAllowClippingKey
except ImportError:
    NSWorkspaceDesktopImageAllowClippingKey = u'NSWorkspaceDesktopImageAllowClippingKey'
from Foundation import NSURL

picture_path = "/Library/Desktop Pictures/<YOURJPGHERE>.JPG"

# generate a fileURL
file_url = NSURL.fileURLWithPath_(picture_path)

# make image options dictionary
options = {
    NSWorkspaceDesktopImageScalingKey: NSImageScaleProportionallyUpOrDown,
    NSWorkspaceDesktopImageAllowClippingKey: True
}

# get shared workspace
ws = NSWorkspace.sharedWorkspace()

# iterate over all screens
for screen in NSScreen.screens():
    # tell the workspace to set the desktop picture
    # on 10.6 this returns 0 (failure) or 1 (success)
    # on 10.8 this returns a tuple (result, error); success is (True, None)
    result = ws.setDesktopImageURL_forScreen_options_error_(
        file_url, screen, options, None)

chad_fox
Contributor II

We're using a config profile for the desktop background, then a script I got from JAMF for the screen saver.

bb1d4fcdf408437fa8441eebe8599c13

!/bin/sh

sleep 15

currentUser=ls -l /dev/console | awk {' print $3 '}

su $currentUser -c "/usr/bin/defaults -currentHost write com.apple.screensaver moduleDict -dict path /System/Library/Frameworks/ScreenSaver.framework/Resources/Computer Name.saver"

exit 0

thoule
Valued Contributor II

My scripts for screen saver management are here: https://github.com/tmhoule/ScreenSaverManagement The script runs via LaunchA and allows you to specify minimum times for the SS to kick in or if password is required.

robertojok
Contributor

rderewianko this script looks great where does one put it?

robertojok
Contributor

When the script listed by rderewianko is pushed via a policy for 10.11.3 it fails with the error Script result: _RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.

Any reason why this is the case anyone?

PeterClarke
Contributor II

This discussion is actually a little confusing, since it covers THREE different things.

  1. Pre-Login Screen Backgrounds
  2. Post-Login Screen Backgrounds
  3. Screen Savers

Both Similar and Different techniques may be employed in resolving each of these.

The Pre-Login background is now less supported by Apple then was earlier the case.
Apple have now unfortunately chosen to make this much more difficult..
So that a forced system modification is now required (10.10 & 10.11) - which contradicts with SIP on 10.11..
I've not looked at this problem, lately, so it's possible that there might be some other resolution, other then by changing the system backdrop pattern ? Although I think not.
So to implement this, I think you have to disable SIP, or include the image in a pre-loaded system image.
- Either way it would get replaced by the Apple 'default' after each system version update.
- and would have to be re-implemented once more.
Where as it once use to be a simple defaults write operation..

I would be interested to know if anyone has an interesting solution to this particular part of problem.

The Post-Login is easy.. and is user specific.
That can be done with config profiles or other means.
In our Labs, we currently use an adaptive, self-optimising scripted solution (which auto-adjusts to accommodate different screen sizes)

This is what the prior solution given by rderewianko is seeking to do.
- Although that seems to be a complex solution, and would still suffer from 'Aspect Ratio' problems..
- By clipping the picture - any text items on the backdrop picture may not always be ideally placed..

I prefer my scripted solution, (not shown) which uses a script to simply copy the 'correct sized' image, after having previously pre-calculated the required size.

In essence a 'fixed' desktop picture is used, (fixed path) but that fixed picture it itself swapped with the chosen picture. - So 'Backdrop picture' is actually 'a variable'.

Changing the user background picture then simply involves changing the 'picture set'.
(with the optimal picture replaced each time the picture set is changed)
We use this to periodically change the screen backgrounds a few times a year.

A limitation though is that the mechanism was not designed to support constantly changing screen backgrounds - which some people use (i.e. change screen background every 5 minutes)
Although with a relatively minor modification this could easily be support too.
(In that case the configuration may randomly pick from a picture library folder)
(we simply need to pre-optimise all of the pictures in the selected picture library folder,
to match the screen resolution, otherwise aspect-ratio issues may arise.)

The third discussed item: 'Screen Saver', can be done via Config profile or other means.

The 'problematic one' is changing the pre-login screen backdrop on a SIP protected System..

In response to Robert Ojok, the reason why the WindowServer is throwing an error..
is because this requires the process to run "while a user is logged in"..
- Since otherwise there is no associated 'window server'.
This points out another failing of that particular technique.
- Which is also an issue, that any solution has to deal with..

(I have to wait until someone does login - and then record the screen size of that associated window server, and then store that value for later use, so that it's available system-wide, and can then be used without requiring any later active logins) Thus enabling optional screen backdrops to be changed any at time, whether uses are logged in or not.

To do that a one-time login is required to 'gather' the screen resolution used by the attached display.
(in fact i recalculate this at each user login - so the system is adaptive to screen resolution changes - although not instantly so)

RobertAlviar
New Contributor II

@ chad.fox

thank you for the response. i have followed your settings for desktop background and will test it.

for the screensaver script, may i ask how to set it up?
will it also work for El Capitan?
once the script is applied on the machine one time will it always work everytime a new user logs in?

thanks,
Robert :)