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

Find the currently displayed desktop image UNIX
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...]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[6,364 views]  

Find the currently displayed desktop image | 9 comments | Create New Account
Click here to return to the 'Find the currently displayed desktop image' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Shorter version
Authored by: fm on Oct 02, '03 11:38:00AM

To convert an "HFS path" to an "Unix path" and back you can use:

-- HFS to Unix

posix path of "Mac HD:A Folder:Another One:"

-- will return:
-- "/Mac HD/A Folder/Another One/"

-- UNIX to HFS:

posix file "/aFile.txt"

-- will return:
-- file "Mac HD:aFile.txt"

So the script can be made shorter (and probably quicker) this way:

on run
tell application "Finder" to return POSIX path of (desktop picture as alias)
end run



[ Reply to This | # ]
Shorter version
Authored by: Apollo18Pnut on Oct 02, '03 05:55:22PM

splendid!

now to figure out how to display the currently-rotated-in desktop...



[ Reply to This | # ]
Find the currently displayed desktop image
Authored by: MtnBiker on Oct 02, '03 06:00:48PM

Something I'd like to see too. I have hundreds of photos for my desktop, collected since OS 9. I sometimes want to know the title of the photo, and there isn't a way.

Useful to be able to show original in finder too!

---
Hermosa Beach, CA USA



[ Reply to This | # ]
Shorter version
Authored by: Apollo18Pnut on Oct 02, '03 06:02:01PM
Incorporating the comment above:

#!/bin/sh

FILEPATH=`osascript -e "tell application \"Finder\" to return POSIX path of (desktop picture as alias)"`

/sw/bin/Esetroot -scale -center $FILEPATH


[ Reply to This | # ]
Quoted Form!
Authored by: dhawes on Oct 04, '03 08:20:14PM

Note from this hint:
http://www.macosxhints.com/article.php?story=20030805175235977
>quoted form of "/path/to/some/cool file"
> Returns: "'/path/to/some/cool file'"

so it would look like this:

#!/bin/sh
FILEPATH=`osascript -e "tell application \"Finder\" to return quoted form of POSIX path of (desktop picture as alias)"`
/sw/bin/Esetroot -scale -center $FILEPATH

---
-----
www.cocoaobjects.com



[ Reply to This | # ]
Version with rotating desktops
Authored by: Scarab on Oct 02, '03 11:08:37PM
The plist file gets updated even if the Finder doesn't so you can get the name of the image, but not the path.
The script could be as below which gets the path from the finder and the name from the plist.

#!/bin/sh

FILEPATH=`osascript -e 'tell application "Finder" to return POSIX path of (container of (desktop picture as alias) as alias)'`
FILEPATH=$FILEPATH`defaults read com.apple.Desktop | grep LastName | tail -1 | cut -f 2 -d "=" | cut -f 2 -d '"'`

/sw/bin/Esetroot -scale -center "$FILEPATH"
I added "s around $FILEPATH as the path and name arn't escaped, also the command assumes that the image name doesn't contain a "

[ Reply to This | # ]
Version with rotating desktops
Authored by: GaelicWizard on Oct 03, '03 03:37:30PM

Woohoo! I've been trying to figure out how to do this since I purchased the Digital Blasphemy CD! Thanx a whole bunch!

JP

---
Pell



[ Reply to This | # ]
Version with rotating desktops
Authored by: Apollo18Pnut on Oct 07, '03 01:11:31PM

Nope, that doesn't work. com.apple.Desktop does not keep track of what the currently-rotated-in background image is.



[ Reply to This | # ]
Solve the real problem...
Authored by: RalfM on Oct 06, '03 12:19:36AM

Or, to address the real problem here, you can just get WindowShade X, which not only brings roll up back to the Mac, but also allows you to make ANY window transparent. True transparency, not image window faking. I have mine set to do so when I control-double-click on the title bar.

http://www.unsanity.com/haxies/wsx/

Very nice app.

Ralf

PS I do realise that for some people finding out the name of the current desktop image is the real problem for other reasons, not for faking transparent windows. R.



[ Reply to This | # ]