How do I reliably get the file name of the current background picture? 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) &amp; "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) &amp;amp; "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!
Try 

/usr/libexec/PlistBuddy -c 'Print :Background:default:ImageFilePath' ~/Library/Preferences/com.apple.desktop.plist