When I put the following line in ~/.xbindkeysrc
GNOME correctly launches application vlc
.
"vlc"
XF86Calculator
The problem is that I'd like to run a shell script. When I put the following in ~/.xbindkeysrc
GNOME doesn't launch my script but calculator.
"/home/menteith/bin/audio.sh"
XF86Calculator
Why is that? The script is executable and works as expected when is run from command line.
UPDATE
Thanks to @PRATAP I know know that when I use a compiled program in ~/.xbindkeysrc
(i.e. not a bash script) and press XF86Calculator
button for the first time it launches my program, but when I press XF86Calculator
button for the second time I launches calculator instead.
UPDATE 2
Thanks to , @Raffa I tried yet another solution. I wrote a simple C program:
#include <stdio.h>
#include <stdlib.h>
int main() {
puts("Starting now:");
system("killall -s1 xbindkeys; /home/menteith/bin/audio");
return 0;
}
It kills xbindkeys
and then runs wrapper, which in turn run the script. However, it still fails to work. After second time and next times calculator
is being launched.
UPDATE 3 My script switched between audio from monitor (HDMI) and audio from PC.
#!/usr/bin/env bash
output=$(pactl list cards |grep 'Active Profile:' | cut -d ':' -f 3)
if [ $output == "analog-stereo" ]; then
out="hdmi-stereo"
else
out="analog-stereo"
fi
echo test
# Set the choosen card profile as sink
pactl set-card-profile "alsa_card.pci-0000_00_1f.3" "output:${out}"
# Set the default sink to the new one
pacmd set-default-sink "alsa_card.pci-0000_00_1f.3.${out}" &> /dev/null
# Redirect the existing inputs to the new sink
for i in $(pacmd list-sink-inputs | grep index | awk '{print $2}'); do
pacmd move-sink-input "$i" "alsa_card.pci-0000_00_1f.3.${out}" &> /dev/null
done
Workaround
Tried it on Ubuntu 19.10
contents of
myscript.sh
file.contents of
.xbindkeysrc
file.Once you logged in,
run
xbindkeys --poll-rc
. the key XF86Calculator should run your script.Reference for --poll-rc option https://wiki.archlinux.org/index.php/Xbindkeys and see the comment below the answer in this link https://askubuntu.com/a/1126410/739431
Step # One:
Firstly: I would suggest modifying the
~/.xbindkeysrc
file by clearing the file first then please copy and paste the following code into the file replacingKey_Name
with your actual key name so it will look like this:Secondly: restart
xbindkeys
by running the following command in the terminal:Finally: try the configured key and see if it works as expected.
Step # Two:
Please inspect system settings under Keyboard Shortcuts like in the image below:
If there is a hot key configured for Launch calculator here, then it should be disabled. Otherwise, it might interfere with
xbindkeys
and capture the hot-key press preventing your script from running and running the calculator instead.Step # Three:
Another place to look into is the
/usr/share/X11/xkb/symbols/pc
file.Firstly: open the file in the
gedit
editor by running the following command in the terminal:Secondly: look for a line that contains
XF86Calculator
in it. It will look something like this:Comment out this line by adding a
//
before it like this:Take note of the Key_Name in
<Key_Name>
and save and close the file.Thirdly: edit your
~/.xbindkeysrc
file replacingXF86Calculator
with the noted Key_Name in step Secondly above. It should look like this:Save and close the file.
Fourthly: Clear the xkb settings cache by running the following command in the terminal:
Fifthly: reboot your system to activate your new xkb configuration or reload the new xkb configuration by setting an xkb map layout using the following command in the terminal:
Finally: start
xbindkeys
by running the following command in the terminal:Then try your Hot-Key. If nothing happens, restart
xbindkeys
by running the following command in the terminal:Now, try your Hot-Key again and see if it works as expected.
Best Of Luck