Skip to content

Instantly share code, notes, and snippets.

@ducdigital
Created December 7, 2018 12:27
Show Gist options
  • Save ducdigital/c5e218a78493c219a33661885eebe076 to your computer and use it in GitHub Desktop.
Save ducdigital/c5e218a78493c219a33661885eebe076 to your computer and use it in GitHub Desktop.
Auto-lock your KDE when bluetooth device disconnected
#!/bin/bash
isLocked=false
macaddress=00:00:00:00:00:00
while true; do
connected=$(bluetoothctl connect $macaddress)
if [[ $connected == *"org.bluez.Error.Failed"* ]]; then
if $isLocked; then
sleep 5
else
loginctl lock-session
isLocked=true
sleep 15
fi
else
isLocked=false
fi
sleep 1
done
@ducdigital
Copy link
Author

For this script to work, you will need to have bluetoothctl available and have your device paired.

Change the macaddress variable to your device MAC address

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment