3

This question already has an answer here:

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!

marked as duplicate by Mark, Monomeeth Sep 5 at 21:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

Try

/usr/libexec/PlistBuddy -c 'Print :Background:default:ImageFilePath' ~/Library/Preferences/com.apple.desktop.plist
  • 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
0

You can type:

defaults write com.apple.dock desktop-picture-show-debug-text -bool TRUE;killall Dock

and this will print the complete path on the Desktop image. So viewing your desktop you'll see the file name and path.

To remove the file name from the desktop just type:

defaults delete com.apple.dock desktop-picture-show-debug-text;killall Dock

More info on this is given here.

Not the answer you're looking for? Browse other questions tagged .