Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Get the name of the current desktop image' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Get the name of the current desktop image
Authored by: beauh on May 11, '06 01:17:21AM

[code]defaults read com.apple.desktop | grep -A 10 default | grep ImageFilePath | awk -F= '{print $2}' | sed -e 's/";/"/'[/code]



[ Reply to This | # ]
Get the name of the current desktop image
Authored by: 6502 on May 11, '06 04:46:42AM
Thanks! That was helpful, but when I ran it, the result was the path to an image that was NOT being displayed as my desktop image. However, both of these worked to produce the same results as the AppleScript...
defaults read com.apple.desktop | grep -A 10 1983938400 | grep LastName | awk -F= '{print $2}' | sed -e 's/";/"/'

defaults read com.apple.desktop | grep -A 10 default | grep LastName | awk -F= '{print $2}' | sed -e 's/";/"/'
...and this worked to find the name of the image on my second monitor...
defaults read com.apple.desktop | grep -A 10 552268546 | grep LastName | awk -F= '{print $2}' | sed -e 's/";/"/'
Once again, I think it's important to stress that the way to find the correct property list item is to browse through the .plist file and to use the LastName property. I think that if you've only ever displayed one image as your desktop image since your last clean install, the ImageFilePath field in the default property list entry is going to match the file referenced in the LastName field, but if you are randomizing your screens, they are going to be different. Also, if you are anything like me where I haven't done a clean install on this particular Mac since 10.2, the .plist file is going to have a lot of obsolete and redundant entries and the ImageFilePath won't have any relationship at all to the present location of your image files. So, anyway... this is the AppleScript that I derived from your code...
set my_desktop to (do shell script ("defaults read com.apple.desktop | grep -A 10 1983938400 | grep LastName | awk -F= '{print $2}' | sed -e 's/\";/\"/'")) as text

set my_desktop2 to (do shell script ("defaults read com.apple.desktop | grep -A 10 552268546 | grep LastName | awk -F= '{print $2}' | sed -e 's/\";/\"/'")) as text

display dialog my_desktop & " • " & my_desktop2
...where "1983938400" and "552268546" are the .plist items that store the names of my current desktop images.

[ Reply to This | # ]