Posts Tagged ‘capslock’

24
Feb

linux capslock notify

   Posted by: Muhammed YÜRÜRDURMAZ    in Linux, python

Eer benim gibi durumunu dizüstünüzde ışık olmadığından dolayı göremiyorsanız aşağıdaki script işinizi görebilir.

bu scripti capsnotify.py ismiyle bir yere kaydedin.

daha sonra kullandığınız masaüstü ortamının otomatik başlangıç bölümüne ayarlayın.


#!/usr/bin/
import pygtk
pygtk.require(’2.0′)
import pynotify
import sys
import gtk
import os
import time

__author__="xmaster"
__date__ ="$Feb 24, 2010 11:14:16 AM$"

def get_status():
    status = None
    p = os.popen("/usr/bin/xset q")
    while 1:
        line = p.readline()
        if not line: break
        if line.find("Caps") > -1:
            status = line[21:25].strip()
            break
    p.close()
    return status

def show_status(status):
    if status == "on":
        uri = "file:///usr/share/icons/gnome/scalable/devices/keyboard.svg"
        n = pynotify.Notification("Caps Lock On", "", uri)
    else:
        uri = "file:///usr/share/icons/gnome/scalable/devices/keyboard.svg"
        n = pynotify.Notification("Caps Lock Off", "", uri)

    n.set_timeout(500)
    if not n.show():
        print "Failed to send notification"
        sys.exit(1)

if __name__ == ‘__main__’:
    if not pynotify.init("Caps toggle"):
        print "Unable to initialize Python "
        sys.exit(1)
    old_status = None
    while 1:
        status = get_status()
        if old_status is None:
            old_status = status
        if status != old_status:
            show_status(status)
            old_status = status
        time.sleep(0.5)

Bookmark and Share
Tags: , , , ,

Tags: , , , ,

Switch to our mobile site