Get the name of the current desktop image

May 10, '06 07:30:00AM

Contributed by: Anonymous

I was replying to a question in the forums when I realized that this would make a great tip for the main site. Just like the original poster, I have a lot of desktop images, and sometimes I can't remember the name of the one that's currently displayed when I want to edit it (or trash it). So here's the AppleScript that I came up with to solve that problem...

tell application "System Events"
  set my_desktop to value of (property list item "LastName" of ¬
  property list item "1983938400" of property list item ¬
  "Background" of property list file ¬
  ((path to preferences as Unicode text) & ¬
  "com.apple.desktop.plist"))
    
  display dialog my_desktop
end tell
This script looks in the com.apple.desktop.plist file in your user's Library/Preferences folder for the name of the current desktop image. On my Mac running 10.4.5, there are actually several plist items under Background, each of which contain entries for desktop images that are not being displayed, so it took some poking around to find the correct path.

Apparently, there are some variations in the way that this .plist file looks. For this to work on your own system, you should open your own com.apple.desktop.plist file with the Property List Editor.app, and see where the value for your current desktop image is kept. Then change the value in the script (1983938400 in the above code) to match the value of the appropriate LastName entry for your current desktop image.

I have my Mac set to cycle through the images kept in a single "Screens," folder and I have double-checked that it will snag the name of the file again after the image has cycled a few times. This also works with two-monitor setups. I'll leave the modification for two monitors to your own ingenuity.

Comments (17)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20060507041822864