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.