Find the currently displayed desktop image

Oct 02, '03 10:09:00AM

Contributed by: Apollo18Pnut

I've been using Eterm (available in the unstable branch of Fink) as a pseudo-transparent terminal for X11.app. The way the "transparency" works is pretty simple; you just tell it what your background image is using a utility called Esetroot (included in the Eterm package), and Eterm acts as a "viewport" into that image. Pretty cool, even though it's not true transparency. But I had to keep running Esetroot every time I changed my background image. So, I wrote an AppleScript and a shell script wrapper to figure out what my background image is.

The AppleScript (I called it "applesetroot.scpt"):


tell application "Finder"
  set currentPicture to ((the desktop picture) as string)
end tell

(* change Finder : delimiters to Unix / delimiters *)
(* get the parts of the path *)
set OldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to ":"
set picturePathParts to text items of currentPicture

(* trim off the name of the disk *)
set theLengthOfPicturePathParts to the ¬
  length of picturePathParts
set picturePathParts to items 2 thru ¬
  theLengthOfPicturePathParts of picturePathParts

(* fill in / delimiters *)
set ReplaceString to "/"
set AppleScript's text item delimiters to ReplaceString
set unixPicturePath to picturePathParts as text
set AppleScript's text item delimiters to OldDelims
set unixPicturePath to "/" & unixPicturePath

unixPicturePath
The shell script wrapper ("applesetroot")

#!/bin/sh

FILEPATH=`osascript /Users/tim/bin/applesetroot.scpt`

/sw/bin/Esetroot -scale -center $FILEPATH
Caveat: I still haven't figured out how to make this work with a rotating background image. Finder still thinks "desktop picture" is whatever it was set to before rotation was selected.

[robg adds: I haven't tested this one...]

Comments (9)


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