Beryl emacs toggle

Submitted by ormiret on Sat, 30/06/2007 - 02:31.

I've hacked up a little script to toggle emacs. It is very hacked together and there are a load of things I can think of to fix/improve.

The most obvious would be replacing the dbus-send command with the python dbus support, but after a couple of hours of looking at messages telling me that methods didn't exist to match the patterns I was using to call them I gave up. The pipes to get the IDs should probably be implemented in python too...

#!/usr/bin/python
# Python script to use beryl to toggle display of emacs

import os

get_current_id = "xprop -root | grep _NET_ACTIVE_WINDOW\(WINDOW\) | awk '{ print $5 }'"
get_emacs_id = "xwininfo -root -children | grep emacs@ | awk '{ print $1 }'"
get_root_id = "xwininfo -root | grep id: | awk '{ print $4 }'"

current_id = int(os.popen(get_current_id).readlines()[0], 16)
try:
    emacs_id = int(os.popen(get_emacs_id).readlines()[0], 16)
except IndexError:
    # Emacs isn't running
    os.spawnlp(os.P_NOWAIT, 'emacs', 'emacs')
    exit 
root_id = int(os.popen(get_root_id).readlines()[0], 16)

if current_id == emacs_id:
    minimise = "dbus-send --type=method_call --dest=org.freedesktop.beryl " + \
               "/org/freedesktop/beryl/core/allscreens/minimize_window " + \
               "org.freedesktop.beryl.activate string:root int32:%i "%root_id + \
               "string:window int32:%i"%emacs_id
    os.popen(minimise)
else:
    activate = "dbus-send --type=method_call --dest=org.freedesktop.beryl " + \
               "/org/freedesktop/beryl/core/allscreens/activate_window " + \
               "org.freedesktop.beryl.activate string:root int32:%i "%root_id + \
               "string:window int32:%i"%emacs_id
    os.popen(activate)


( categories: )