This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Get/set current wallpaper

Tags: None
(comma "," separated)
waterkip
Registered Member
Posts
20
Karma
0

Get/set current wallpaper

Tue Aug 25, 2009 9:49 pm
Hi,

I wonder is it possible to get/set the current wallpaper via the command line?
I saw viewtopic.php?f=15&t=66064&hilit=get+current+wallpaper where the dbus call is explained to reload the configuration. (Didn't want to hijack the thread).

But I either want:

1) To be able to set the wallpaper via the command line
2) To be able to get the wallpaper via the command line
3) Call a script after the wallpaper changes

I want to darken a background for conky to get a darker bg which is set by feh.

Currently I just hardcode the wallpaper and after every KDE login I convert that background from color to b/w. If option 3 is available I only need to call the script once (when the bg has changed.

PS. Using KDE 4.3


waterkip, proud to be a member of KDE forums since 2008-Oct.
ruphy
KDE Developer
Posts
19
Karma
0
OS

Re: Get/set current wallpaper

Wed Aug 26, 2009 5:32 pm
hmm... can't you simply select your own picture from the desktop settings dialog?


ruphy, proud to be a member of KDE forums since 2008-Oct.
waterkip
Registered Member
Posts
20
Karma
0

Re: Get/set current wallpaper

Wed Aug 26, 2009 7:12 pm
Sorry? I don't understand you.

This is what I have.

Code: Select all
#!/bin/bash

PATH=/usr/bin/:/bin

## KDE 4.3
# WALL_PAPER=$(qdbus org.kde.plasma-desktop /MainApplication reparseConfiguration)
## KDE3:
# WALL_PAPER=$(dcop kdesktop KBackgroundIface currentWallpaper 1)

WALL_PAPER=$HOME/pics/aruba_2009/img_0199.jpg
GRAY_PAPER=$HOME/.conkybg.png

# Check md5 to see if we have to run convert
F_MD5SUM=$GRAY_PAPER.md5
MD5SUM=$(cat $F_MD5SUM 2>/dev/null)
NEW_MD5=$(md5sum "$WALL_PAPER" | awk '{print $1}')

if [ "$MD5SUM" != "$NEW_MD5" ] || [ ! -e "$GRAY_PAPER" ] ; then
    $HOME/bin/convert-wallpaper.rb "$WALL_PAPER" "$GRAY_PAPER"
    echo "$NEW_MD5" > $F_MD5SUM
    cat $F_MD5SUM
fi

feh --bg-scale "$GRAY_PAPER"

pgrep conky &>/dev/null
[ $? -ne 0 ] && conky


The KDE 4.3 part is not working.
Now I saw online some posts claiming you can retreive it from a plasmarc file, by doing

Code: Select all
grep 'wallpaper=' $HOME/.kde/share/config/plasma-desktop-appletsrc


But I get too much results, including wallpapers I do not use.

I want to select a wallpaper within KDE and then have something telling me (the script) that the wallpaper has changed, so it can run and update the wallpaper set by feh.


waterkip, proud to be a member of KDE forums since 2008-Oct.
ruphy
KDE Developer
Posts
19
Karma
0
OS

Re: Get/set current wallpaper

Thu Aug 27, 2009 8:20 pm
sorry, I'm not sure i get it.
can't you simply select $HOME/.conkybg.png as wallpaper image? I assume the image that you will want will always be found there.

the background is iirc also cached, so you might want to clear the relevant files into $KDEHOME/cache-$(hostname)/ where $KDEHOME is usually .kde or .kde4.


ruphy, proud to be a member of KDE forums since 2008-Oct.
waterkip
Registered Member
Posts
20
Karma
0

Re: Get/set current wallpaper

Thu Aug 27, 2009 11:15 pm
ruphy wrote:sorry, I'm not sure i get it.
can't you simply select $HOME/.conkybg.png as wallpaper image? I assume the image that you will want will always be found there.


No, the .conkybg.png is a darker background then my own. I need it because conky uses fake transparency, so it just takes a copy of the root wallpaper. However, KDE uses a different window and not the root. So I want to grab the KDE wallpaper, make it darker (conky doesn't support shading) and use feh to set it as a root wallpaper, which then gets used by conky. Making it look like conky is really cool.

So when a KDE wallpaper changes I need to update the script to use the same wallpaper as KDE. If I can extract that data from KDE I can do this without having to set it in the script.

I just want something like:

$ kde --get-wallpaper
/home/user/path/to/wallpaper

and/or

$ kde --set-wallpaper /home/user/path/to/wallpaper


waterkip, proud to be a member of KDE forums since 2008-Oct.
ruphy
KDE Developer
Posts
19
Karma
0
OS

Re: Get/set current wallpaper

Sun Aug 30, 2009 11:17 pm
ah, ok, i see!

for set is somewhat difficult, while if you just want to get it you could try to parse .kde4/share/config/plasma-desktop-appletsrc, and find the right section of the form [Containment][$id][Wallpaper][image]

just open the file in a text editor, it should be easy enough.


ruphy, proud to be a member of KDE forums since 2008-Oct.
waterkip
Registered Member
Posts
20
Karma
0

Re: Get/set current wallpaper

Mon Aug 31, 2009 9:12 am
ruphy wrote:ah, ok, i see!

for set is somewhat difficult, while if you just want to get it you could try to parse .kde4/share/config/plasma-desktop-appletsrc, and find the right section of the form [Containment][$id][Wallpaper][image]

just open the file in a text editor, it should be easy enough.


Easy? Have you seen that file? I have no idea how I can extract the correct wallpaper of the correct id of the currently active wallpaper. A simple grep will not work, since many many wallpapers (often duplicates) are shown...

Code: Select all
grep 'wallpaper=' $HOME/.kde/share/config/plasma-desktop-appletsrc
wallpaper=/usr/share/wallpapers/Air
wallpaper=/usr/share/wallpapers/Air
wallpaper=/usr/share/wallpapers/Air
wallpaper=/home/wesleys/pics/bla/dsc00810.jpg
wallpaper=/usr/share/wallpapers/Air
wallpaper=/home/wesleys/pics/aruba_2009/img_0199.jpg
wallpaper=/home/wesleys/pics/aruba_2009/img_0199.jpg
wallpaper=/home/wesleys/pics/aruba_2009/img_0199.jpg
wallpaper=/usr/share/wallpapers/Air


Perhaps I need to read the code of the plasma to figure out how it picks the correct section..


waterkip, proud to be a member of KDE forums since 2008-Oct.
ruphy
KDE Developer
Posts
19
Karma
0
OS

Re: Get/set current wallpaper

Mon Aug 31, 2009 1:17 pm
there is not any duplicacy, each of those lines corrisponds to a different containment. just get the one that you want, or change them all.


ruphy, proud to be a member of KDE forums since 2008-Oct.
waterkip
Registered Member
Posts
20
Karma
0

Re: Get/set current wallpaper

Mon Aug 31, 2009 2:08 pm
ruphy wrote:there is not any duplicacy, each of those lines corrisponds to a different containment. just get the one that you want, or change them all.
That is not really portable across KDE users...

Eitherway, fixed for me by doing this, although a nicer way would be appreciated, like the KDE3.5 way.

Code: Select all
grep 'wallpaper=' $HOME/.kde/share/config/plasma-desktop-appletsrc  | tail -2 | head -1 | awk -F= '{print $NF}'
f1r3br4nd
Registered Member
Posts
16
Karma
0

Re: Get/set current wallpaper

Wed Jun 09, 2010 4:36 pm
Eitherway, fixed for me by doing this, although a nicer way would be appreciated, like the KDE3.5 way.

Code: Select all
Select all
    grep 'wallpaper=' $HOME/.kde/share/config/plasma-desktop-appletsrc  | tail -2 | head -1 | awk -F= '{print $NF}'




In KDE 4.4.2 it looks like the wallpaper variable doesn't give you the full path to the actual image. That path is actually a directory. So if grep returns your wallpaper as "/usr/share/wallpapers/FOO", the actual wallpaper images are in "/usr/share/wallpapers/FOO/contents/images" and there are multiple images there, apparently one for each resolution. So now the question is, is there a command-line way to get the current screen resolution?

Oh, and by the way, it looks like the file type of plasma-desktop-appletsrc is now incorrectly reported as 'binary' so the grep statement should be:

Code: Select all
Select all
    grep --binary=files=text 'wallpaper=' $HOME/.kde/share/config/plasma-desktop-appletsrc  | tail -2 | head -1 | awk -F= '{print $NF}'


...in order for you to get the actual matching strings in your output.
f1r3br4nd
Registered Member
Posts
16
Karma
0

Re: Get/set current wallpaper

Wed Jun 09, 2010 5:09 pm
Okay, here's how you get your current wallpaper in KDE 4.4.2. It'll probably totally break when you upgrade anything or add some new eyecandy package or breathe on it wrong, but it works for now.
Code: Select all
FOO=$(grep --binary-files=text 'wallpaper=' $HOME/.kde/share/config/plasma-desktop-appletsrc  | tail -2 | head -1 | awk -F= '{print $NF}')"/contents/images/"$(xrandr -q --current|grep \\*|tail -n 1|awk '{print $1}')".png"


Now the question is, what's the most efficient thing to do with FOO? The nobrainer would be to redirect the output to a file that conky reads everytime it cycles. But from a performance point of view, shouldn't I store it in an environment variable? Is there a way to set a global environment variable for already-running processes? And either one is better than actually running the whole thing every time conky cycles, because it's not as if users change screens that often.

Is there a way to run a shell script automatically every time the screen resolution or wallpaper changes?

Thanks.
f1r3br4nd
Registered Member
Posts
16
Karma
0

Re: Get/set current wallpaper

Wed Jun 09, 2010 6:11 pm
D'oh, I'm wrong. There isn't a 1-to-1 correspondence between the resolution and the wallpaper chosen, and (should have realized) most resolutions don't have a corresponding wallpaper. So I guess I'll just hardcode the closest one and be done with it. Ugh, how ugly. Can't wait till dbus catches up.

By the way, since dcop still exists in the repository for 10.04, has anybody tried just using that? How did it work out for you?


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora, watchstar