scripting compiz; could use some perl regexp help

Paul Johnson pauljohn32 at gmail.com
Sat Jun 7 23:59:55 UTC 2008


Hey, kids!

Changing to Ubuntu has had side effects.  A version of compiz that
works with no fussing!

Did you know that compiz is on the dbus, so you can tell it what to do
in scripts?

Awesome.  With 1000s of backgrounds, I want the wallpaper to change on
all the sides of the cube all the time.  What fun!

You can set images into the backgrounds array of the cube like so,
where I drop in A.jpg and B.jpg.  You can put in as many as you want.

dbus-send --print-reply --type=method_call
--dest=org.freedesktop.compiz
/org/freedesktop/compiz/cube/screen0/backgrounds
org.freedesktop.compiz.set
array:string:"/home/pauljohn/Backgrounds/B.jpg,/home/pauljohn/Backgrounds/A.jpg"

Here's where I need your perl regexp help.  I'm writing something to
query the background array and then change some of them.  But I'm
mentally blocked on how to select the part between the quotation marks
here and convert to Perl array.

You can ask compiz to tell you the images it currently has and it
returns a bunch of text:


$ dbus-send --print-reply --type=method_call
--dest=org.freedesktop.compiz
/org/freedesktop/compiz/cube/screen0/backgrounds
org.freedesktop.compiz.get
method return sender=:1.15 -> dest=:1.28 reply_serial=2
   array [
      string "/home/pauljohn/Backgrounds/A.jpg"
      string "/home/pauljohn/Backgrounds/B.jpg"
      string "/home/pauljohn/Backgrounds/C.jpg"
      string "/home/pauljohn/Backgrounds/D.jpg"
      string "/home/pauljohn/Backgrounds/E.jpg"
   ]

In the Perl script, I run that method, and want to convert it to an
array that just has the quoted parts in the elements.


So far I have a bunch of really klunky code, stupid.  Why can't I see
a way to just grab the bits between" " into a vector?

Here's the example:

my $getBG = "dbus-send --print-reply --type=method_call
--dest=org.freedesktop.compiz
/org/freedesktop/compiz/cube/screen0/backgrounds
org.freedesktop.compiz.get";

my $existingBG = `$getBG`;

$existingBG =~ m/\".*\"/g;
$existingBG =~ s/string/,/g;
$existingBG =~ s/array//g;
$existingBG =~ s/\[//g;
$existingBG =~ s/\]//g;
$existingBG =~ s/.*,//;
$existingBG =~ s/.*$//;


@grepOut = grep(/".*"/, split(/,/, $existingBG));


print "Existing: $existingBG \n";

print "grepOut: @grepOut \n";


Here's the output I see when I run that:


$ ./pjcubebackground.pl -d /usr/local/share/Backgrounds/Italy/
,Existing: method return sender=:1.15 -> dest=:1.37 reply_serial=2

 "/usr/local/share/Backgrounds/Italy/dot_italy_iii_palermo_35.jpg"
      , "/usr/local/share/Backgrounds/Italy/dot_newfoundland_iceberg.jpg"
      , "/usr/local/share/Backgrounds/Italy/DOT_Italy_XIII_Venice_039.jpg"
      , "/usr/local/share/Backgrounds/Italy/DOT_Italy_XIII_Venice_063.jpg"
      , "/usr/local/share/Backgrounds/Italy/DOT_Italy_XVII_Rome_Collosseo_09.jpg"


grepOut method return sender=:1.15 -> dest=:1.37 reply_serial=2

 "/usr/local/share/Backgrounds/Italy/dot_italy_iii_palermo_35.jpg"
        "/usr/local/share/Backgrounds/Italy/dot_newfoundland_iceberg.jpg"
        "/usr/local/share/Backgrounds/Italy/DOT_Italy_XIII_Venice_039.jpg"
        "/usr/local/share/Backgrounds/Italy/DOT_Italy_XIII_Venice_063.jpg"
        "/usr/local/share/Backgrounds/Italy/DOT_Italy_XVII_Rome_Collosseo_09.jpg"


The first element in the grepOut array has that erroneous stuff before
the image name.  Other than that, it is OK.

-- 
Paul E. Johnson
Professor, Political Science
1541 Lilac Lane, Room 504
University of Kansas




More information about the ubuntu-users mailing list