#!/bin/bash # Command to kill all the previous instances of the current bash file. kill -9 $(pgrep -f ${BASH_SOURCE[0]} | grep -v $$) # Function to get the Linux distribution name function get_distro() { if [[ -f /etc/os-release ]] then # On Linux systems source /etc/os-release echo $ID else # On systems other than Linux (e.g. Mac or FreeBSD) uname fi } DISTRIBUTION_NAME=$(get_distro) LINUX_MINT="linuxmint" if [ "$DISTRIBUTION_NAME" = "$LINUX_MINT" ] then # Code related to hook SCREEN_LOCK and SCREEN_UNLOCK events in MINT distribution dbus-monitor --session "type='signal',interface='org.cinnamon.ScreenSaver'" | while read x; do case "$x" in *"boolean true"*) echo "SCREEN_LOCKED";; *"boolean false"*) echo "SCREEN_UNLOCKED";; esac done else # Code related to hook SCREEN_LOCK and SCREEN_UNLOCK events in UBUNTU distribution dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" | while read x; do case "$x" in *"boolean true"*) echo "SCREEN_LOCKED";; *"boolean false"*) echo "SCREEN_UNLOCKED";; esac done fi