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

mcr834

macrumors newbie
Original poster
Apr 29, 2014
10
0
Hi everyone,

I am using random wallpaper on my Mac and it changes every hour. Since I use different artwork I would like to have the name of the current wallpaper displayed on my screen.

I found excellent solution for that except that it doesn't work. I am talking about GeekTool and this script here:

http://www.macosxtips.co.uk/geeklets/system/desktop-wallpaper-name/

The script is 1083 days old and thats probably the reason why it doesn't work.

Can anyone help improving that script please?

Others have asked this question here before but its not resolved:

https://forums.macrumors.com/threads/1525299/

I really think that script is the way to go. Just need to find out why it doesn't work!
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Hi everyone,

I am using random wallpaper on my Mac and it changes every hour. Since I use different artwork I would like to have the name of the current wallpaper displayed on my screen.

I found excellent solution for that except that it doesn't work. I am talking about GeekTool and this script here:

http://www.macosxtips.co.uk/geeklets/system/desktop-wallpaper-name/

The script is 1083 days old and thats probably the reason why it doesn't work.

Can anyone help improving that script please?

Others have asked this question here before but its not resolved:

https://forums.macrumors.com/threads/1525299/

I really think that script is the way to go. Just need to find out why it doesn't work!

What OS version are you running? Post the output of the script/commands you ran. I answered a similar question some while ago and in researching that I found that Mavericks stores the wallpaper names/paths in a database now. I would have to research/look it up again but al least we would have a starting point.
 

mcr834

macrumors newbie
Original poster
Apr 29, 2014
10
0
What OS version are you running? Post the output of the script/commands you ran. I answered a similar question some while ago and in researching that I found that Mavericks stores the wallpaper names/paths in a database now. I would have to research/look it up again but al least we would have a starting point.

Hi, I am using Os 10.9.2. The script I linked simply does not show the name of current wallpaper as it should. I don't use any commands. I just load that script with the GeekTool:

http://projects.tynsoe.org/en/geektool/

This should produce a box on the screen with the file name of the current wallpaper but it inly shows the box.

If I didn't answer your question please ask again and thanks for trying to help!
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Let's forget about GeekTool for a moment and run the script in AppleScript Editor.

Edit : Ok. Found what was wrong. Try this :

Code:
tell application "System Events"
	
	set a to (picture of first desktop) as POSIX file
	
	set b to a as string
	
	set AppleScript's text item delimiters to ":"
	
	set y to end of text items of b
	
	set AppleScript's text item delimiters to "."
	
	text item 1 of y
end tell

--or

(*
tell application "System Events"
	
	set a to (picture of first desktop)
	
	set AppleScript's text item delimiters to "/"
	
	set y to end of text items of a
	
	set AppleScript's text item delimiters to "."
	
	text item 1 of y
end tell
*)
 
Last edited:

mcr834

macrumors newbie
Original poster
Apr 29, 2014
10
0
Hi sorry for the delayed reply (I am from Europe so it was night here). What this scripts do is to produce the words "Solid Gray Medium" as an result.

This is in my case the background color around the wallpaper in the case I select center (which I do not, I choose "Fill Screen")

In Mavericks the information about the wallpaper is not anymore stored in the com.apple.desktop.plist but in desktoppicture.db:

http://derflounder.wordpress.com/20...om-librarypreferencescom-apple-desktop-plist/

I think it will be very hard to find something to replace "picture of first desktop" in your script.

Maybe instead we should try to make Applescript that would change a wallpaper to random one and at the same time list its name?

I think these two posts can be helpful.

http://stackoverflow.com/a/19608773
https://github.com/pipwerks/OS-X-Wallpaper-Changer
 
Last edited:

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium

mcr834

macrumors newbie
Original poster
Apr 29, 2014
10
0
Well one of the posts you mentioned combined with your script you suggested yesterday did help! Thank you for that!

Here is the script for anyone that wants to use it:

Code:
tell application "System Events"
	
	set a to (do shell script "sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.picture_id=7 and preferences.data_id=data.ROWID\"") as POSIX file
	
	set b to a as string
	
	set AppleScript's text item delimiters to ":"
	
	set y to end of text items of b
	
	set AppleScript's text item delimiters to "."
	
	text item 1 of y
end tell
 

kryten2

macrumors 65816
Mar 17, 2012
1,114
99
Belgium
Great. It's good practice to never put a do shell script statement inside a tell application block as it is part of the StandardAdditions dictionary and to reset AppleScript's text item delimiters to their default setting. For this script you don't need the tell application "System Events" block.

Code:
set a to (do shell script "sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.picture_id=7 and preferences.data_id=data.ROWID\"") as POSIX file
set b to a as string
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set y to end of text items of b
set AppleScript's text item delimiters to "."
set c to text item 1 of y
set AppleScript's text item delimiters to ASTID
return c
 

chown33

Moderator
Staff member
Aug 9, 2009
10,731
8,407
A sea of green
Great. It's good practice to never put a do shell script statement inside a tell application block as it is part of the StandardAdditions dictionary and to reset AppleScript's text item delimiters to their default setting. For this script you don't need the tell application "System Events" block.

Code:
set a to (do shell script "sqlite3 ~/Library/Application\\ Support/Dock/desktoppicture.db \"SELECT data.value FROM preferences INNER JOIN data on preferences.key=16 and preferences.picture_id=7 and preferences.data_id=data.ROWID\"") as POSIX file
[B]set b to a as string[/B]
set {ASTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set y to end of text items of b
set AppleScript's text item delimiters to "."
set c to text item 1 of y
set AppleScript's text item delimiters to ASTID
return c

Could you post the typical value b after line 2 executes (I hilited it in bold)? I'd like to see an example of what the string looks like.

If it's just a classic Mac OS pathname, like "HD:someDir:anotherDir:File Name Here.jpg", then there's a more concise way to get the "File Name Here" part than going through all the delimiter setting and cruft. Basically, it goes like this:
Code:
echo "HD:someDir:anotherDir:File Name Here.png" | awk -F":" '{print $NF}' | awk -F"." '{print $1}'
Or you could add that pipeline (less the echo) to the sqlite3 command in the first line, and be done in one.

If the pathname produced by sqlite3 is a Posix pathname, then simple change the -F":" to -F"/" and it should work the same. But if it's a Posix pathname, the 'basename' command is even simpler to use.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.