Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 14, 2013, 09:18 AM   #1
moonracer
macrumors newbie
 
Join Date: Jan 2013
Script to display current wallpaper in use.

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
moonracer is offline   0 Reply With Quote
Old Jan 14, 2013, 09:36 AM   #2
superscape
macrumors regular
 
Join Date: Feb 2008
Location: 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 is offline   0 Reply With Quote
Old Jan 14, 2013, 10:00 AM   #3
superscape
macrumors regular
 
Join Date: Feb 2008
Location: 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.
superscape is offline   0 Reply With Quote
Old Jan 14, 2013, 11:38 AM   #4
moonracer
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Quote:
Originally Posted by superscape View Post
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
moonracer is offline   0 Reply With Quote
Old Jan 14, 2013, 12:00 PM   #5
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
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.
ArtOfWarfare is offline   0 Reply With Quote
Old Jan 14, 2013, 01:23 PM   #6
moonracer
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Quote:
Originally Posted by ArtOfWarfare View Post
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 is offline   0 Reply With Quote
Old Jan 14, 2013, 01:43 PM   #7
moonracer
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
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 is offline   0 Reply With Quote
Old Jan 14, 2013, 07:31 PM   #8
moonracer
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
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 is offline   0 Reply With Quote
Old Jan 14, 2013, 07:58 PM   #9
moonracer
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
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 is offline   0 Reply With Quote
Old Jan 14, 2013, 08:43 PM   #10
moonracer
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
I found the following command on the web and it displays a wallpaper filename but it as well displays the wrong one.

defaults read com.apple.desktop Background |grep -m 1 LastName | awk '{print $3}'| sed -e 's/;//g' | sed -e 's/"//g'
moonracer is offline   0 Reply With Quote
Old Jan 14, 2013, 08:57 PM   #11
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by moonracer View Post
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.)
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Jan 14, 2013, 10:02 PM   #12
moonracer
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
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
moonracer is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
GeekTool Script for the Random Wallpaper Name Display eklisiarh Mac Programming 8 Apr 30, 2014 10:02 PM
Geektool script to display Activity Monitor? elgrayso Community Discussion 0 Mar 7, 2014 10:51 PM
Wallpaper changer script? Riku7 Mac Programming 5 Mar 4, 2014 11:39 AM
disable sleep but turn off the display using command or script? appleluck iMac 10 Dec 30, 2013 10:14 AM
App/Script to turn 1 display on/off Scottland Mac Applications and Mac App Store 0 Oct 13, 2013 12:57 PM

Forum Jump

All times are GMT -5. The time now is 12:56 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC