Disable Set Desktop Picture in Photos
By Morgan Rowe | 04 Dec 2015
Photos was launched in 2015 with OS X 10.10.3. The application was designed to replace both iPhoto, an application designed to help you manage and touch up your photos; and Aperture, a beefier version of iPhoto aimed at power users or photographers who wanted higher fidelity when working with their images.
The new Photos application came with a slew of new features, one of which is the new Share options. Among the new sharing options, there is one for setting a selected photo as the desktop wallpaper called 'Set Desktop Picture'. This is great for users that don't need to have their wallpaper enforced, but for Mac admins who're trying to configure a specific wallpaper, it's a bit of a nuisance. As far as I can tell, Photos uses its own way of configuring the Mac's wallpaper rather than reaching out to existing workflows that can be deleted or 'locked'.
I couldn't see any preferences in Photos' property list files and there was no database to play around with in the Application Support directory. However, I found that Photos stores all of the images that have been shared via Set Desktop Picture to a directory named Photos Desktop in
~/Library/Containers/com.apple.Photos/Data/Library/Caches/ on OS X Yosemite or
~/Library/Containers/com.apple.Photos/Data/Library/Application Support/ for OS X El Capitan. Removing all write access to these folders effectively disables Photos' Set Desktop Picture feature. Great, but how do we enforce this for all users?
The script below simply removes write permissions of the Photos Desktop directory, which disallows the application from caching the photos and consequently changing the desktop wallpaper. This probably causes an error, but Photos handles it nicely, not even throwing up an error message to annoy users.
The most up to date script with comments and human readable white spacing can be viewed on GitHub, but you can also view it here:
#!/bin/bash whoami=$(/usr/bin/whoami) photosAppVersion=$(/usr/bin/defaults read /Applications/Photos.app/Contents/version.plist CFBundleShortVersionString) photosContainer=/Users/$whoami/Library/Containers/com.apple.Photos photoDesktopYos=$photosContainer/Data/Library/Caches/Photos\ Desktop photoDesktopElCap=$photosContainer/Data/Library/Application\ Support/Photos\ Desktop photosDesktopCheck=$photosContainer/.DisabledSetDesktopPicture chmod=/bin/chmod mkdir=/bin/mkdir touch=/usr/bin/touch /bin/sleep 3 if [ ! -f "$photosDesktopCheck" ]; then if [[ "$photosAppVersion" == "1.2"* ]]; then photoDesktop=$photoDesktopElCap else photoDesktop=$photoDesktopYos fi if [ -d "$photosContainer" ]; then if [ -d "$photoDesktop" ]; then $chmod 000 "$photoDesktop" $touch "$photosDesktopCheck" else $mkdir "$photoDesktop" $chmod 000 "$photoDesktop" $touch "$photosDesktopCheck" fi fi fi exit 0
Save this script somewhere to the target machine. Scripts like these usually live in
/usr/local/bin/. I'm going to call mine
We have the script but we'd like it to run automatically for all users. We can achieve this using
launchd. We don't want the script to be running all the time as a user may never open Photos, so the script should only fire when Photos opens or is being used. To accomplish this, we simply need to save a daemon into
/Library/LaunchAgents/. I used the following commands to make the daemon. Remember to prepend each command with sudo if you're not running the commands as root:
defaults write /Library/LaunchAgents/com.ehcho.disable-set-desktop-picture-in-photos.plist Label "com.ehcho.disable-set-desktop-picture-in-photos"
defaults write /Library/LaunchAgents/com.ehcho.disable-set-desktop-picture-in-photos.plist WatchPaths -array
defaults write /Library/LaunchAgents/com.ehcho.disable-set-desktop-picture-in-photos.plist WatchPaths -array-add "~/Library/Containers/com.apple.Photos"
defaults write /Library/LaunchAgents/com.ehcho.disable-set-desktop-picture-in-photos.plist ProgramArguments -array
defaults write /Library/LaunchAgents/com.ehcho.disable-set-desktop-picture-in-photos.plist ProgramArguments -array-add "/usr/local/bin/disable-photos-set-desktop-picture.sh"
defaults write /Library/LaunchAgents/com.ehcho.disable-set-desktop-picture-in-photos.plist RunAtLoad -bool true
Finally, we'll need to ensure the permissions are correct for both the daemon and the script itself:
chown root:wheel /usr/local/bin/disable-photos-set-desktop-picture.sh
chmod 755 /usr/local/bin/disable-photos-set-desktop-picture.sh
chown root:wheel /Library/LaunchAgents/com.ehcho.disable-set-desktop-picture-in-photos.plist
chmod 644 /Library/LaunchAgents/com.ehcho.disable-set-desktop-picture-in-photos.plist
Restarting the machine will automatically load the daemon for all users, or it can be loaded manually:
launchctl load -w /Library/LaunchAgents/com.ehcho.disable-set-desktop-picture-in-photos.plist
The script has been tested on both OS X Yosemite and El Capitan. There were some slight differences between where the cached photos were saved between operating systems, but the script accommodates this easily. Enjoy!