One Wallpaper/Background per desktop/workspace in Ubuntu with Icons

It seems the current best solution with respect to multiple wallpapers involves giving up desktop icons. I’ve written a rather hackish alternative, which instead gives up instantaneous transitions between one wallpaper and the next (they now take about half a second). The code is reproduced below, but I recommend grabbing the original here (which preserves pretty indentation).

# written Joseph Bylund, 2011/10/12
# this script watches for desktop changes, and when it finds one it changes the background. Currently this is a hackjob, but it
# should work if you fix the paths and number the files you'd like to use as 1.jpg, 2.jpg, 3.jpg (for workspaces 1,2,3
# respectively). You can even use xml files as per the cosmos background as your backgrounds, just rename to 1.xml,
# 2.xml ... You'll also have to change the extension to xml from jpg.
# also update the path_to_bg_files to where you're keeping your background files.

use strict;

use Time::HiRes qw( nanosleep );

my $extension = "jpg";

my $user = `whoami`;

my $path_to_bg_files = "/home/$user/Desktop/multi_wallpaper_test";

my $workspace_width = `wmctrl -d|head -n 1`;
$workspace_width =~ s/.*WA: [^ ]* //;
$workspace_width =~ s/x.*//;
$workspace_width = int($workspace_width);
print "width = $workspace_width\n";

my $window_manager = &get_window_manager;
print "using $window_manager\n";
my $last_workspace = &get_workspace($window_manager,$workspace_width);
my $current_workspace = $last_workspace;

my $counter = 0;

$current_workspace = &get_workspace($window_manager,$workspace_width);
if($current_workspace != $last_workspace)
$last_workspace = $current_workspace;
system("gconftool --type string --set /desktop/gnome/background/picture_filename \"$path_to_bg_files/$current_workspace.${extension}\"");
nanosleep(int(0.5*10^9)); # increase sleep timer to reduce cpu usage, decrease to improve response time

sub get_workspace
my $window_manager = shift;
my $workspace_width = shift;
my $current_workspace;
if($window_manager eq "metacity")
$current_workspace = `wmctrl -d|grep \\*`;
$current_workspace =~ s/.*Workspace//g;
$current_workspace =~ s/\s*//g;
my $current_vp = `wmctrl -d`;
$current_vp =~ s/.*VP: //;#cut off leading
$current_vp =~ s/,.*//;#cut off trailing
$current_workspace = $current_vp/$workspace_width + 1;

sub get_window_manager
my $lines = `wmctrl -d|wc -l`;
if($lines > 1)

One Response to “One Wallpaper/Background per desktop/workspace in Ubuntu with Icons”

  1. Peter James Says:

    This looks like something I would like to try.
    As a relative newbie to Linux I have this question:
    What do I do with the script?
    Would you mind making a tutorial for beginners?
    I need Crossloop (Windows Application) for customer support.
    This is my reason for not dropping Windows.
    Thank you very much!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: