Unlock gnome/mate/i3 locks from the command line

I run multiple desktop environments, and they all come with their own screen locking tool. Sometimes I want to unlock a system remotely, that means from the command line. The script below can unlock mate, gnome and i3lock.

Raw
#!/bin/bash

echo "Unlock"
echo
echo " - [m]ate"
echo " - [g]nome"
echo " - [i]3lock"

uid=$(id -u "${USER}")
if pgrep -U "$uid" -af i3lock > /dev/null; then
  choice="i"
elif pgrep -U "$uid" -af mate-screensaver > /dev/null; then
  choice="m"
else
  read -r -s -n1 choice
fi

echo -e "\nChoice: ${choice}"

if [ "$choice" == "m" ]; then
  mate-screensaver-command  --unlock
elif [ "$choice" == "g" ]; then
  loginctl unlock-sessions
elif [ "$choice" == "i" ]; then
  pkill -f i3lock
else
  echo "Unknown choice ${choice}"
fi

0 comments

Reply

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo