KDE: Control background from command line

My friend Keith has done rotating backgrounds on his desktop for a while, and I was thinking today that it would be kind of nice to do that as well.

Step 1: Download some files and put them in a directory: ~/Wallpapers
Step 2: Write a script that picks a file at random and calls xsetbg

Problem 1: xsetbg and KDE don’t get along.
Solution: DCOP!

DCOP is the automation language of KDE. It’s also, thanks to kdcop (GUI client) and dcop(1) (command line client) easy to browse available interfaces.

A few minutes of experimentation show that the right invocation is:
dcop kdesktop KBackgroundIface setWallpaper $file 4
the 4 is a magic number that means stretch it to fit the screen while preserving aspect ratio. All the constants (I got as far as 8 before I got bored with the subtle variations):

0
none
1
center
2
tile
3
center tile
4
stretch aspect
5
stretch tile
6
stretch all
7
center
8
stretch vertical

Then I put it in crontab, but of course you have to make sure that dcop is in your path (on SUSE, KDE is in its own little sandbox in /opt/kde3/bin) and that you have your DISPLAY set.

This entry was posted in tech. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>