Figured a way out.
Keep a python script running at the background and use the serial
library in python to connect to a particular serial port. Now serial write
the data from arduino whenever the desired action in executed in arduino. Read the value written on serial in python script and based on that value execute shell command for locking and unlocking the system, which are as follows:
gnome-screensaver-command -l
(to lock)
gnome-screensaver-command -d
(to unlock)
Python code:
import serial, os
port_name = '/dev/ttyACM0' # Change accordingly
arduino = serial.Serial(port_name, 9600)
while True:
word = str(arduino.readline())
if word == 'l': # Lock the screen
os.system('gnome-screensaver-command -l')
elif word == 'u': # Unlock the screen
os.system('gnome-screensaver-command -d')
Now using Serial.write()
function of arduino, write 'l'
or 'u'
on the serial based on your requirement (RFID Swipe as in my case).
Happy Hacking :-)