Categories
Computers

More uzbl

I’ve managed to get uzbl and awesome to talk with one another. Without using awesome-client and uzblctrl or socat. It turned out, upon further examination, that awesome-client is just a bash script for communicating on dbus and uzblctrl is just a simple c program for communicating over a socket.

These findings suggested that if I could get Lua to talk over a socket and if I could come up with a python script to talk over dbus, I would have a more flexible means for getting uzbl and awesome to talk with one another. Luckily for me, python has a dbus module and lua has luasockets.


We’ll start with the python dbus stuff:

import dbus

def dbus_send(cmd):
    bus = dbus.SessionBus()
    awesome = bus.get_object('org.naquadah.awesome.awful',
                             '/')
    awesome_iface =  dbus.Interface(awesome,
                                   dbus_interface = 'org.naquadah.awesome.awful.Remote')
    awesome_iface.Eval(cmd)

This little piece of code duplicates the business end of awesome-client allowing Lua code to be executed. I haven’t managed to put much useful code around this yet. None-the-less, it works.

The second piece of code is a piece of Lua code for talking to a socket. Before I could get it to work I had to install luasockets.

 local socket = require("socket.unix")

function socket_send(s_file, data)
    s = socket()
    s:connect(s_file)
    s:send(data)
    s:close
end

This piece of code is the basic idea and I have something similar in my awesome config file for changing the url in a uzbl instance. I have it paired with a promptbox in awesome so that when I type the url into the promptbox, the url is passed to a Lua function which sends a “uri” command to uzbl using the socket file.

The above dbus code is used to help tie everything together. I have bound the python script to a key using the uzbl config file. By doing this, I can tell awesome what socket file to communicate with and therefore I can now use an awesome prompt to control uzbl.

Well, I thought it was slick when I got it running anyway.

UPDATE: I was reminded in the comment section that as of Awesome version 3.4.x, the DBUS service name changed.  I’ve udpated that python code snippet accordingly.  For posterity’s sake, if running Awesome prior to v3.4, the service name should be ‘org.awesome’ and the dbus interface is ‘org.awesome.Remote.’

5 replies on “More uzbl”

Hello. Just ot update your post, the correct name for awesome’s services is now “org.naquadah.awesome.awful”, and not just org.awesome. A quick look at the awesome-client script will show that… So the correct function is now:

def dbus_send(cmd):
bus = dbus.SessionBus()

awesome = bus.get_object(‘org.naquadah.awesome.awful’,
‘/’)
awesome_iface = dbus.Interface(awesome,
dbus_interface = ‘org.naquadah.awesome.awful.Remote’)
awesome_iface.Eval(cmd)

Thanks for your post!

Thanks for the comment.

Amusingly, I’d actually gone through the exercise of updating my script, but I’d forgotten about the post. I’ve updated the post to include your changes.

I’m glad someone else found it useful.

thank you very much for this working snippet. i tried to make awesome-client understand multiple quotes, but using python for this is so much easier. i can now modularise my awesome config just by sending it functions or overwriting them on the fly. thats truly awesome

Leave a Reply

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