More improvements (working version)
1. Create the following three files at these locations (next version i'll include ability to specify your open/close script locations as parameters
~/bin/laptop-lid/open
~/bin/laptop-lid/closeCode:#!/bin/bash notify-send "lid opened" #play a open sound aplay /usr/lib/openoffice/basis3.1/share/gallery/sounds/sparcle.wav #change Pidgin status purple-remote 'setstatus?status=available&message=I am here...'
Code:#!/bin/bash aplay /usr/lib/openoffice/basis3.1/share/gallery/sounds/falling.wav #change Pidgin status purple-remote 'setstatus?status=away&message=My laptop lid is closed...'
~/bin/laptop-lid/event
Make it run after login..Code:#!/usr/bin/env python import os import dbus, gobject from dbus.mainloop.glib import DBusGMainLoop class LaptopLid: def __init__(self): self.dbusSystemObject = "org.gnome.PowerManager.Backlight" self.dbusSystemObjectPath = "/org/gnome/PowerManager/Backlight" self.acpiLIDstatePath = "/proc/acpi/button/lid/LID0/state" #this may vary dending on your system self.scriptPath="~/bin/laptop-lid" self.state="closed" dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) self.bus = dbus.SessionBus() self.bus.add_signal_receiver(self.cb_func, dbus_interface=self.dbusSystemObject, path=self.dbusSystemObjectPath) self.loop = gobject.MainLoop() self.loop.run() def cb_func(self,message,sender=None): # if(laptopLidState==) f = open(self.acpiLIDstatePath, 'r').read() if f.count("open") > 0 : #and self.state=="closed" : print "opened" os.system('sh '+self.scriptPath+'/open') self.state = "open" elif f.count("closed") > 0 : # and self.state=="open": print "closed" os.system('sh '+self.scriptPath+'/close') self.state = "closed" l = LaptopLid()
1 open : system > preferences > startup applications
2. click add
3. name : DBUS Laptop Lid Event Detector
4. command : python ~/bin/laptop-lid/event
Testing...
Test it by opening terminal and typing :
Code:python ~/bin/laptop-lid/event



Adv Reply



Bookmarks