GeekTool Script for the Random Wallpaper Name Display

Discussion in 'Mac Programming' started by eklisiarh, Apr 29, 2014.

  1. eklisiarh macrumors newbie

    Joined:
    Apr 29, 2014
    #1
    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:

    http://forums.macrumors.com/showthread.php?t=1525299

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

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    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.
     
  3. eklisiarh thread starter macrumors newbie

    Joined:
    Apr 29, 2014
    #3
    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!
     
  4. kryten2, Apr 29, 2014
    Last edited: Apr 29, 2014

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    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
    *)
     
  5. eklisiarh, Apr 29, 2014
    Last edited: Apr 30, 2014

    eklisiarh thread starter macrumors newbie

    Joined:
    Apr 29, 2014
    #5
    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
     
  6. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #6
  7. eklisiarh thread starter macrumors newbie

    Joined:
    Apr 29, 2014
    #7
    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
     
  8. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #8
    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
     
  9. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #9
    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.
     

Share This Page