Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 3856  / 1 Year ago, wed, may 3, 2023, 9:00:35

I made a simple bash script to display a notification whenever my capslock key is pressed. It works fine when I call it like bash capsnotify.sh.



The problem now is when I bind my above script to capslock key using xbindkeys tool it doesn't work as required. It shows a notification caps ON when my caps is on but it doesn't show caps OFF notification when my caps is off instead it again shows the caps ON notification.



capsnotify.sh



#!/bin/bash

value=$(xset -q | awk '/Caps/ {print $4}')

if [ "$value" == "on" ]

then
notify-send "caps ON"

elif [ "$value" == "off" ]

then
notify-send "caps OFF"
fi


.xbindkeysrc



"bash /home/ranveer/capsnotify.sh"
m:0x2 + c:66


So, the problem is after binding my caps lock key on both events(on/off) it shows caps ON notification.


More From » 12.04

 Answers
5

What worked for me is adding sleep before the call to my script in xbindkeys. So, now my .xbindkeysrc looks like



"sleep 0.1 && bash /home/ranveer/capsnotify.sh"


I believe it works by adding sleep because the call to xset to query the state of CapsLock happens before the Xserver has toggled the state which might be due to my window manager which grabs the key event and doesn't process it super-quickly and thus X toggles a bit later.


[#37067] Thursday, May 4, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
igeonlothe

Total Points: 370
Total Questions: 121
Total Answers: 114

Location: United States Minor Outlying Island
Member since Fri, Feb 5, 2021
3 Years ago
;