Set Desktop Background

phil_self
New Contributor

Hi All,

We have just implemented Casper a few days ago but we are struggling with the following.

A desktop background (bespoke one) has been set as part of an image and the "Desktop and Screen Saver" prefpane has been disabled so users cannot change it. However a new background can be set using right click "Set as Desktop Background" and we cannot find a way to stop this working.

Ideally we would like to either disable the right click option OR create a policy to reset the background pic to our bespoke one every day/week/restart.

Any ideas would be greatly appreciated

1 ACCEPTED SOLUTION

gregneagle
Valued Contributor

Don't use a script (but thanks for referencing my work) -- it's too hard to enforce the desktop picture via a script.
Install a profile. Perhaps one like this:
https://github.com/gregneagle/profiles/blob/master/desktop_picture.mobileconfig

View solution in original post

9 REPLIES 9

andysemak
Contributor

I use a configuration profile to enforce the desktop background. Works well for us.

You can lock the desktop picture in the Restrictions option.

BOBW
Contributor II

I use script attached, run as launchAgent and set to run every 10 minutes - works great, the user can change the desktop but within ten minutes it will change back

#!/usr/bin/python
# Universal enforce wallpaper script for 10.9 and up
# Based on https://gist.github.com/gregneagle/6957826#file-gistfile1-py
from AppKit import NSWorkspace, NSScreen
from Foundation import NSURL
from platform import mac_ver
from subprocess import call
from os import system
from os import getlogin
import sqlite3

# Set path here for 10.9+
picture_path = "/usr/Management/Images/Desktop.jpg"

u = getlogin()
if ( u == '_atsserver') or ( u == 'root'):
    print "Nothing to do as " + u

v, _, _ = mac_ver()
v = float('.'.join(v.split('.')[:2]))

desktop_db = '/Users/' + u + '/Library/Application Support/Dock/desktoppicture.db'
conn = sqlite3.connect(desktop_db)
conn.text_factory = str
c = conn.cursor()


def commit_changes():
    #------------------------
    conn.commit()
    conn.close()

def get_current_wallpaper():
    #------------------------
    c.execute("SELECT * from data")
    for row in c.fetchall():
        return row[0]
    commit_changes()


if (v == 10.9) or (v == 10.10):
    print str(v) + " detected..."
    current = get_current_wallpaper()
    if (current != '/Library/Desktop Pictures/Custom.jpg'):
        print 'Incorrect wallpaper detected.  Changing...'
        file_url = NSURL.fileURLWithPath_(picture_path)
        options = {}
        ws = NSWorkspace.sharedWorkspace()
        for screen in NSScreen.screens():
            (result, error) = ws.setDesktopImageURL_forScreen_options_error_(file_url, screen, options, None)
    else:
        print 'Wallpaper is correct.'

gregneagle
Valued Contributor

Don't use a script (but thanks for referencing my work) -- it's too hard to enforce the desktop picture via a script.
Install a profile. Perhaps one like this:
https://github.com/gregneagle/profiles/blob/master/desktop_picture.mobileconfig

BOBW
Contributor II

@gregneagle yes I agree, much better answer.... just tested and works great!

Wish I knew more about how to create these from scratch...... Unfortunately we don't have casper yet and trying to wrestle with Profile Manager is a $%^&&*(

davidacland
Honored Contributor II
Honored Contributor II

Not sure how long you've got to wait before you can drop profile manager but Munki can install profiles and might be a more stable solution for you in the interim.

iOSGenius
New Contributor III

Hello so this profile that is created can it be created without Casper as we only have it for our iPads and not the Macs.

Could i use apple configurator to create this profiles for the Mac, or does Casper have features than apple configurator to do this.

Thank you,

Dan Fernandez
IT Specialist of Educational Technology
iOS Expert - iOSGenius.com
Office: (708) 449-3165 x3588
Cell 1: (312) 877-8488

iOSGenius
New Contributor III

@davidacland

So i created a profile in apple configurator and installed it only thing is i can still change the background, and it is listed under user profiles as wallpaper block

but in the details is listed as Restriction (iOS Only) same for settings

from the link you provided from github - https://github.com/gregneagle/profiles/blob/master/desktop_picture.mobileconfig

not sure what or how to create this profile to use on the mac or is this only for Casper or munki

Thank you,

Dan Fernandez
IT Specialist of Educational Technology
iOS Expert - iOSGenius.com
Office: (708) 449-3165 x3588
Cell 1: (312) 877-8488

davidacland
Honored Contributor II
Honored Contributor II

Hi @iOSGenius

If you copy the text from the GitHub link and save as a file with the .mobileconfig extension. Then you can upload it into Casper and deploy to the devices. You just have to change the key

<key>override-picture-path</key> <string>/Library/Desktop Pictures/Abstract.jpg</string>

to the path of your desktop picture.

Normally I would use a standard config profile in Casper in the restrictions payload which can also set the desktop background and keep it enforced.

carlox
New Contributor

Hello
i am working with munki to deploy software and configurations. the .mobilconfig datei work great for some standard background but i dont find some place to put a custom background. i try with "installations --> items to copy" but is not working for some files in munki server tree. i am sure that can not to be so hard but i doit ever with a .dmg packet and run ok (IN this packet). Now in a .mobilconfig i am lost.

Please tell me: How to copy a "bg.jpg" with .mobileconfig with munki? Or better: How to copy some files with munki without another re-packet job?

Best Regards Carlos