1 # Automatically lock the screen when bluetooth beacon moves out of range
4 from beacontools
import BeaconScanner
, IBeaconFilter
, IBeaconAdvertisement
9 global isHere
, screenSaverSetActive
, screenSaverGetActive
11 def handler(signum
, frame
):
15 def callback(bt_addr
, rssi
, packet
, additional_info
):
19 sessionBus
= dbus
.SessionBus()
20 screenSaver
= sessionBus
.get_object("org.gnome.ScreenSaver", "/org/gnome/ScreenSaver")
21 screenSaverIface
= dbus
.Interface(screenSaver
, 'org.gnome.ScreenSaver')
22 screenSaverSetActive
= screenSaverIface
.get_dbus_method("SetActive")
23 screenSaverGetActive
= screenSaverIface
.get_dbus_method("GetActive")
26 # scan for all iBeacon advertisements regardless from which beacon
27 #scanner = BeaconScanner(callback,
28 # packet_filter=IBeaconAdvertisement
31 signal
.signal(signal
.SIGINT
, handler
)
35 scanner
= BeaconScanner(callback
,
36 device_filter
=IBeaconFilter(uuid
="INSERT YOUR UUID HERE")
43 print("Beacon is here")
45 print("Beacon is gone")
46 if not screenSaverGetActive():
47 print("Locking screen")
48 screenSaverSetActive(True)