Script to print the name of the current desktop

Just a python script, to print the name of the current desktop. Could be useful to pipe to conky or something.

#!/usr/bin/env python
from Xlib import display, Xatom
dsp = display.Display()
rootwin = dsp.screen().root

DESKTOP_NAMES = dsp.intern_atom("_NET_DESKTOP_NAMES")
CURRENT_DESKTOP = dsp.intern_atom("_NET_CURRENT_DESKTOP")

def get_names():
    names = rootwin.get_full_property(DESKTOP_NAMES, 0)
    names = names.value.split("\x00")
    return names

def current_desktop():
    return rootwin.get_full_property(CURRENT_DESKTOP, 
                                     Xatom.CARDINAL
                                     ).value[0]

try:
    print get_names()[current_desktop()]
except:
    print "error getting name"

Requires the python bindings for xlib

Advertisements
Script to print the name of the current desktop

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s