Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonracer

macrumors newbie
Original poster
Jan 14, 2013
20
0
Would someone mind putting together a script or point me in the right direction as to how to code and display the currently displayed wallpaper?

I'm using Geektool and would love to have a way to display the current wallpaper filename. I collect nice wallpapers and have so many that it would be nice to keep the filename of each WP being displayed on my desktop.

THere are times when I need to delete or modify a wallpaper depending on how it looks on my desktop and finding it out of hundreds can be a time consuming job.

Any help you can provide would be greatly appreciated!

Cheers,
mr
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
Any use?

Hi,

I'm not familiar with GeekTool. Would an AppleScript be of any help? If so then this will tell you the file name...

Code:
--display the file name
tell application "Finder"
	set theDesktopPic to desktop picture
	set theName to displayed name of theDesktopPic
	display dialog theName
end tell

...whereas this will show you the file itself in the Finder

Code:
--show where the pic is in the Finder
tell application "Finder"
	set theDesktopPic to desktop picture
	set theName to displayed name of theDesktopPic
	reveal theDesktopPic
end tell
 

superscape

macrumors 6502a
Feb 12, 2008
937
223
East Riding of Yorkshire, UK
Ah ha!

Okay, I got a demo copy of GeekTool. Looks like you need to call it from a shell script.

If you saved this applescript...

Code:
tell application "Finder"
	set theDesktopPic to desktop picture
	set theName to displayed name of theDesktopPic
	return theName
end tell

...into a file called picname.scpt (or whatever you like) in your home folder then you can call it as a shell script like this:

Code:
 /usr/bin/osascript ~/picname.scpt 2> /dev/null


Hope that helps.
 

moonracer

macrumors newbie
Original poster
Jan 14, 2013
20
0
Okay, I got a demo copy of GeekTool. Looks like you need to call it from a shell script.

If you saved this applescript...

Code:
tell application "Finder"
	set theDesktopPic to desktop picture
	set theName to displayed name of theDesktopPic
	return theName
end tell

...into a file called picname.scpt (or whatever you like) in your home folder then you can call it as a shell script like this:

Code:
 /usr/bin/osascript ~/picname.scpt 2> /dev/null


Hope that helps.

Many thanks my friend!!!

I have the file created and Geektool pointing to it. It displays a wallpaper filename but not the currently displayed wallpaper. I have my walpapers to shuffle every 15 minutes and the filename is not changing nor is it correct.

Could it be pulling from another screen? Sorry for my lack of Mac knowledge. I have only one Desktop enabled and only one monitor.

Best Regards,
mr
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,558
6,058
So have geektool run the script and update itself every 15 minutes. I haven't used geektool much, but it seems like repeating every 900 seconds for things like weather geeklets is pretty common, so there should be examples available.
 

moonracer

macrumors newbie
Original poster
Jan 14, 2013
20
0
So have geektool run the script and update itself every 15 minutes. I haven't used geektool much, but it seems like repeating every 900 seconds for things like weather geeklets is pretty common, so there should be examples available.


I do have it repeating but just running it in the terminal manually gives me the same results. Outside of GT completely.

It's like the script is not recognizing the currently displayed wallpaper.

No worries. I'll take this and see what I can do with it.

Thank you for your help and the script.

Cheers,
mr
 

moonracer

macrumors newbie
Original poster
Jan 14, 2013
20
0
I found the script below on the web but it generates a window which I don't want.

Got to figure out how to just pull the value from the plist file to display in the Terminal then GT will do its thing.

set plistFolderPath to path to preferences folder from user domain as string
set plistPath to plistFolderPath & "com.apple.desktop.plist"
tell application "System Events"
tell property list file plistPath
tell contents
set theResult to value of property list item "NewChangePath" of property list item "default" of property list item "Background" & "/" & value of property list item "LastName" of property list item "default" of property list item "Background"
end tell
end tell
end tell
display dialog theResult buttons {"Done"} default button 1
 

moonracer

macrumors newbie
Original poster
Jan 14, 2013
20
0
From what I have gathered, using the desktop picture function has been depreciated with the latest version of OS. I'm running 10.8.2

It looks like I will need to parse the file below and pull the info out. Not going to be easy for me but if I get it working, I'll post the solution.

If you have a plist file editor (for example, the one that comes with Developer Tools), open up ~/Library/Preferences/com.apple.desktop.plist. Look at the path /Background/default/NewImageFilePath.


Regards,
mr
 

moonracer

macrumors newbie
Original poster
Jan 14, 2013
20
0
Let me retract what I stated in my previous post. For some reason I have multiple desktop filenames within my com.apple.desktop.plist file for some strange reason.

Superscapes code is pulling from the correct location as the desktop image filename his code displays is within my plist file but so are 3 other filenames of wallpapers. Not sure how to handle this. Maybe these are static walls I chose in the past.

I think I just took two steps back. lol

mr
 

moonracer

macrumors newbie
Original poster
Jan 14, 2013
20
0
I found the following command on the web and it displays a wallpaper filename but it as well displays the wrong one. :confused:

defaults read com.apple.desktop Background |grep -m 1 LastName | awk '{print $3}'| sed -e 's/;//g' | sed -e 's/"//g'
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,558
6,058
If you have a plist file editor (for example, the one that comes with Developer Tools), open up ~/Library/Preferences/com.apple.desktop.plist. Look at the path /Background/default/NewImageFilePath.

I see a key called ImageFilePath in that same spot. It seems to have my current background image. Do you not have the same key? (I also have NewImageFilePath. It contains the exact same path as ImageFilePath, but my desktop image never changes... I set it shortly after taking the picture three years ago... I can't even remember what it was before this anymore.)
 

moonracer

macrumors newbie
Original poster
Jan 14, 2013
20
0
AOW,

Ive made a little progress with the script below.

Code:
defaults read com.apple.desktop Background |grep -m 2 LastName | tail -n 1 | awk '{print $3,$4,$5,$6,$7,$8,$9,$10}' | sed -e 's/;//g' | sed -e 's/"//g'

I skip the first entry and found that the second is my current desktop. You are correct that I have keys prior to each entry but I wasn't sure if those changed or not.

This works for me but now I need to figure out how to use awk to pull the whole line of data (row?) instead of each column. Some of my wall filenames have spaces while others do not.

This script isn't going to be pretty Im sure when a long image filename is selected as my wallpaper with underscores instead of spaces. lol

I can use my renamer app to get rid of the underscores and replace them with spaces but I'm looking for something that's a bit more reliable and bullet proof. The other issue is what if I have more than 9 or 10 occurrences of spaces or 9 or more words. :(

Any suggestions would be greatly appreciated!

Thank you again for your help.

Regards,
mr
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.