Issue setting desktop background on MacBook Airs and via PreStage DEP Enrollment

danny_friedman_
New Contributor III

I have been experiencing a very strange issue with setting desktop backgrounds on new and old El Capitan MacBook Airs. I have also tested for this issue on a new 13" MacBook Pro (retina), 15" MacBook Pro (retina), and on multiple Parallels OS X 10.11 VMs on both a 15" and 13" MacBook Pro (retina) and the issue has not reoccurred.

My two different test MacBook Airs are a 2013 one and a 2015 one. The 2013 MBA received the policy with an "Enrollment" trigger (applied while the QuickAdd package was running), and the 2015 MBA received the policy via a PreStage (Apple DEP) "Enrollment" trigger.

Here is what the issue is. I initially wrote a bash script that is run as a postflight script of a payload-free package. It worked as expected when testing on my VM and on a test MacBook Pro 13" (retina). This is the script:

#!/bin/bash

# copy background to /Library/Desktop Pictures
cp CIVIS_LOGO_REV_WOTM_0715.png "/Library/Desktop Pictures"
chmod 644 /Library/Desktop Pictures/CIVIS_LOGO_REV_WOTM_0715.png
chown root:wheel /Library/Desktop Pictures/CIVIS_LOGO_REV_WOTM_0715.png

# check if /System/Library/User Template/English.lproj/Library/Application Support/Dock exists
if [ ! -d "/System/Library/User Template/English.lproj/Library/Application Support/Dock" ]; then
    mkdir -p "/System/Library/User Template/English.lproj/Library/Application Support/Dock"
fi

# copy desktoppicture.db to /System/Library/User Template/English.lproj/Library/Application Support/Dock
cp desktoppicture.db "/System/Library/User Template/English.lproj/Library/Application Support/Dock"

# set desktop for existing 'civisadmin' account
if [ -d /Users/civisadmin ]; then
    cp desktoppicture.db /Users/civisadmin/Library/Application Support/Dock/
    cp tmp/com.apple.desktop.plist /Users/civisadmin/Library/Preferences/
    chown civisadmin:staff /Users/civisadmin/Library/Application Support/Dock/desktoppicture.db /Users/civisadmin/Library/Preferences/com.apple.desktop.plist
    chmod 644 /Users/civisadmin/Library/Application Support/Dock/desktoppicture.db
    chmod 600 /Users/civisadmin/Library/Preferences/com.apple.desktop.plist
fi

# get logged-in user and assign it to a variable
LOGGEDINUSER=$( ls -l /dev/console | awk '{print $3}' )

# get user home directory
HOMEDIR=$(dscl . -read /Users/$LOGGEDINUSER NFSHomeDirectory | cut -d' ' -f2)

# set desktop for existing for current user account
if [ -d $HOMEDIR ]; then
    cp desktoppicture.db $HOMEDIR/Library/Application Support/Dock/
    cp com.apple.desktop.plist $HOMEDIR/Library/Preferences/
    chown $LOGGEDINUSER:staff $HOMEDIR/Library/Application Support/Dock/desktoppicture.db $HOMEDIR/Library/Preferences/com.apple.desktop.plist
    chmod 644 $HOMEDIR/Library/Application Support/Dock/desktoppicture.db
    chmod 600 $HOMEDIR/Library/Preferences/com.apple.desktop.plist
fi

# restart the dock (user will see the background flash)
killall Dock

exit 0

Again, this script was deployed via a policy triggered on enrollment, and all seemed fine... until I ran this on a 2013 MacBook Air. For whatever reason, it just didn't work. the killall Dock command would flash the screen and for an instant I would see the correct desktop background, but then it would revert to the default El Capitan background. Since I copied CIVIS_LOGO_REV_WOTM_0715.png to the default desktop pictures directory, I could manually set it after the policy failed to properly set the background, but this somewhat defeats the point of even having a policy to accomplish this in the first place.

I then searched the internet for other ways to accomplish setting the desktop background, and of course @rtrouton had written an excellent blog entry about setting desktop backgrounds in Mavericks (Der Flounder). He included the command to set the background via AppleScript:

osascript -e "tell application "System Events" to set picture of every desktop to "/path/to/image.jpg""

I built a package that dumped CIVIS_LOGO_REV_WOTM_0715.png into the default OS X backgrounds location and then ran AppleScript command to set the desktop background as a postflight. It seemed to work perfectly on both the test MacBook Pro and test MacBook Air, so I assumed I was all finished.

Then, I received a new MacBook Air from Apple and imaged it using PreStage DEP deployment. When the computer ran the policy to set the desktop background via AppleScript, the same issue happened that initially occurred when setting the background via the bash script. Just to be sure, I recreated the policy that sets the desktop background using the bash script (rather than AppleScript), erased the computer, and "re-imaged" using the PreStage DEP method. I saw no change, and the script was unable to set the desktop background in the same manner.

Does anyone have an idea what may be going on? I'm really scratching my head here.

3 REPLIES 3

davidacland
Honored Contributor II

It's a tricky one to ensure it works for every user. I've been using the config profile option since 10.10 which works well.

danny_friedman_
New Contributor III

@davidacland , thanks for the response. The only reason that I am not using a Configuration Profile is because I do not want to force a user to have to have this background. I simply just want it to be the default background that new users have when accounts are created or a new machine is deployed. If the user would like to change it at some point, I would always like that to be an option.

Is that possible with a Configuration Profile? Sorry for my naivety on this!

I also don't like how Configuration Profiles just are pushed without any specific order to a machine (or at least, cannot be prevented from being pushed until specific Policies or other Config Profiles are run/pushed – but I do understand the "why" behind this). At least with Policies, I can guarantee that other policies are run prior to another policy based on naming convention (a true policy prioritization would be a nice feature for a future release).

danny_friedman_
New Contributor III

Well, I just tried "re-imaging" via PreStage DEP two more times, taking the original bash script and adding the AppleScript to the end (making the script set the background in two different ways, which I understand is redundant).

The first time, the background flashed twice (for each refresh of the Dock), but didn't set properly. After erasing the machine and trying the exact process again, it somehow worked. I changed no settings. I find this whole thing very bewildering.

Any ideas out there?