Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Latest Lion update broke a simple Geeklet osascript that used System Events to lookup of Background picture names. Running the associated command from the terminal returns the same name, every time, even though the picture is changing every minute.

The code below worked for the primary display on my two headed Mac until this last update:

osascript -e 'tell application "System Events" to get value of (property list item "LastName" of property list item "default" of property list item "Background" of property list file ((path to preferences as Unicode text) & "com.apple.desktop.plist"))'

The secondary display has a hard-coded id where "default" goes; I've used the numeric IDs, everything I can think of.

What is particularly annoying is a dump using just 'property list item "Background' in the above script shows the new file names with the appropriate "LastName". But running the script above always returns the same two names, the initial files shown in the Desktop/Screen Saver preferences.

I'm not an AppleScript or System Events/plist guru, and any help would be appreciated.

--UPDATE--

Modifying the “Spaces” plist on OSX to set default desktops and some experimentation with the "defaults" command led to the following (less than ideal due to the embedded ids, but...) workaround:

osascript -e 'tell application "System Events" to get value of (property list item "LastName" of property list item "722492885" of property list item "" of property list item "spaces" of property list item "Background" of property list file ((path to preferences as Unicode text) & "com.apple.desktop.plist"))'

I'm certainly open to more elegant solutions but they must reflect the changing filename with "Random" set in Desktop Preferences. I'd even like to see a more readable version of what is posted above - all one line. I'm sure there's better ways to lay this out!

share|improve this question
add comment

1 Answer

Try

/usr/libexec/PlistBuddy -c 'Print :Background:default:ImageFilePath' ~/Library/Preferences/com.apple.desktop.plist
share|improve this answer
    
I wish I could do it with defaults read com.apple.Desktop Background but I don't know how to specify default:ImageFilePath. –  lhf May 17 '12 at 23:58
    
This will display a file path, you're correct. Unfortunately, with the "Desktop & Screen Saver" settings of "Change picture every minute" & "Random", this is the path of the first picture selected. It doesn't change as the minutes go by and the background changes. –  Ken Gentle May 18 '12 at 2:37
    
@KenGentle, you're right. It seems that com.apple.desktop.plist does not get this info. Sorry for the noise. –  lhf May 18 '12 at 2:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.