User Tools

Site Tools


Table of Contents

This is a simple perl script showing how you can use perl to communicate with a running instance of uzbl.


For instance, to get a dump of the current html document, you can do this: <socket> 'print @<document.all[0].innerHTML>@'


#!/usr/bin/env perl
# simple perl implementation of uzblctrl, which can be used to query uzbl for stuff.
# usage: <socket> <command>
use strict;
use IO::Socket::UNIX;
use Digest::MD5 qw(md5_hex);
my $path = shift;
my @cmd = @ARGV;
# simple Uzbl socket object
sub Uzbl{
  my $path = shift;
  # connect the socket
  my $socket = IO::Socket::UNIX->new(Type => SOCK_STREAM, Peer => $path) or die $@;
  return sub {
    my $line = shift;
    # generate a end marker
    my $mark = md5_hex(rand());
    # send the command and request endmarker
    print $socket "$line\nprint $mark\n";
    my $str;
    while(my $line = <$socket>){
      #read until end marker
      if($line =~ m/^$mark$/){
        return $str;
      } else {
        $str .= $line;
# create object
my $query = Uzbl($path);
# send command
print $query->("@cmd");
uzblctrl-pl.txt · Last modified: 2016/08/31 14:10 (external edit)