#!/usr/bin/perl # desktop_watcher.pl # 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`; chomp($user); my $path_to_bg_files = "/home/$user/Desktop/multi_wallpaper_test"; my $last_workspace = &get_workspace; my $current_workspace = $last_workspace; while(1) { $current_workspace = &get_workspace; 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 $current_workspace; if(&get_window_manager eq "metacity") { $current_workspace = `wmctrl -d|grep \\*`; chomp($current_workspace); $current_workspace =~ s/.*Workspace//g; $current_workspace =~ s/\s*//g; $current_workspace; } else { my $current_vp = `wmctrl -d`; chomp($current_vp); $current_vp =~ s/.*VP: //;#cut off leading $current_vp =~ s/,.*//;#cut off trailing $current_workspace = $current_vp/&get_workspace_width + 1; # this actually gives only the column at the moment, need to add row } } sub get_workspace_width { my $workspace_width = `wmctrl -d|head -n 1`; chomp($workspace_width); $workspace_width =~ s/.*WA: [^ ]* //; $workspace_width =~ s/x.*//; $workspace_width = int($workspace_width); } sub get_window_manager { my $lines = `wmctrl -d|wc -l`; chomp($lines); if($lines > 1) {"metacity";} else {"compiz";} }