desktop background plist settings not behaving consistently

To automate the process of "cleaning up" my desktop for screencasting purposes, I wrote a bash script, called DesktopClean.sh, that hides all icons on the desktop and changes the background image to something suitably non-distracting. To allow for pre-clean-up-desktop-settings recovery, I added a line that dumps the previous settings into a text file. A second script, DesktopMessUp.sh reads that file and resets the plist settings to the original ones. It seems to work, mostly. I usually have the background set to change every 30 minutes to a random image from a particular folder. After running DesktopMessUp.sh, I get a random image from the correct folder but it's static (no random change every 30 minutes). If I dump the settings into a file before and after, running them through diff shows no difference except for the variable "LastName" which contains the names of the displayed image before and after the scripts ran. In particular, after running DesktopMessUp.sh, the variable Change is correctly set to TimeInterval, ChangeTime to 5 (I tested it out using a 5 sec change setting) and Random is set to 1. Can anyone explain why I'm not recovering the original random bg change every 5 seconds?


Here is DesktopClean.sh:


#!/bin/bash

defaults write com.apple.finder CreateDesktop -bool false

killall Finder

defaults read com.apple.desktop Background>/Users/cytryn/.desktopbgsettings

desktopsettings=`cat /Users/cytryn/.desktopbgsettingsclean`

defaults write com.apple.desktop Background "$desktopsettings"

killall Dock


And here is DesktopMessUp.sh:


#!/bin/bash

defaults write com.apple.finder CreateDesktop -bool true

killall Finder

desktopsettings=`cat /Users/cytryn/.desktopbgsettings`

defaults write com.apple.desktop Background "$desktopsettings"

killall Dock


Here is how I checked the settings:


$ defaults read com.apple.desktop Background > temp1.txt

$ DesktopClean.sh

$ defaults read com.apple.desktop Background > temp2.txt

$ DesktopMessUp.sh

$ defaults read com.apple.desktop Background > temp3.txt

$ diff temp1.txt temp3.txt

iMac, Mac OS X (10.6.8)

Posted on Jun 6, 2012 4:36 PM

Reply
6 replies

Jun 7, 2012 10:37 AM in response to cytryn

ok, looking more closely, you are using the wrong tool for the job. Use these applescripts instead:


1. clearing the desktop

tell application "Finder" to quit

do shell script "defaults write com.apple.finder CreateDesktop -bool false"

tell application "Finder" to launch


tell application "System Events"

set picture rotation of desktop 1 to 0


-- if necessary, you can set the image with the following line. but it ought to remember between runs, since you're not actually changing anything.


-- set picture of desktop 1 to "/path/to'image_file"

end tell


2. restoring the desktop

tell application "Finder" to quit

do shell script "defaults write com.apple.finder CreateDesktop -bool true"

tell application "Finder" to launch


tell application "System Events"

set picture rotation of desktop 1 to 1

end tell


You could probably combine them into one applescript with a toggle of some sort, if you like.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

desktop background plist settings not behaving consistently

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.