Based on @DBinJP's investigation (and here), here is presented a way to the complete solution.
1. Run the following lines as single command (copy them all together and paste in a terminal). This will create a script called kbdbacklight
, that will be placed in /usr/local/bin
to be accessible as shell command system wide.
cat << EOF | sudo tee /usr/local/bin/kbdbacklight && sudo chmod +x /usr/local/bin/kbdbacklight
#!/bin/sh
KBD_BACKLIGHT="/sys/devices/platform/sony-laptop/kbd_backlight"
read VALUE < "\$KBD_BACKLIGHT"
if [ "\${VALUE}" -eq '0' ]; then echo '-1' > "\$KBD_BACKLIGHT"
elif [ "\${VALUE}" -eq '-1' ]; then echo '0' > "\$KBD_BACKLIGHT"
else echo "Something went wrong."; notify-send "Something went wrong."
fi
EOF
Explanation:
The command cat << EOF
will output the next lines until the next string EOF
. These lines will be piped |
to the command tee
that will write them in the file /usr/local/bin/kbdbacklight
. If this operation is successful &&
then give executable permissions chmod +x
to the file. The backslashes \
will escape the special meaning of $
sign within the cat
command.
In the first two lines, the script will read the value of the file /sys/devices/platform/sony-laptop/kbd_backlight
. Then if the value is 0
it will be changed to -1
and vice versa.
Now the script must be accessible as shell command. Type sudo kbdbacklight
end hit Enter. You will be asked for a password to execute the command as root by sudo
.
2. Grant permissions to all users to run the command (our script) without password via sudo
. No matter whether the users belong to the sudoers group or not.
Note: Always use the command visudo
to edit the sudoers
file to make sure you do not lock yourself out of the system – just in
case you accidentally write something incorrect to the sudoers
file.
visudo
will save your modified file to a temporary location and will
only overwrite the real sudoers
file if the modified file can be parsed without errors... source.
For this purpose we will create the file /etc/sudoers.d/kbdbacklight
. Execute the command:
sudo visudo -f /etc/sudoers.d/kbdbacklight
And place the following line as a content of the file. Then save and close the file.
ALL ALL=NOPASSWD: /usr/local/bin/kbdbacklight
Now all users could be able to execute the command sudo kbdbacklight
without password.
3. Create custom keyboard shortcut and bind the script to a desired key (or key combination).
Go to System Settings → Keyboard → Shortcuts (tab) → Custom Shortcuts (section) → Add new +.
In the Custom shortcut window type: [Name: kbdbacklight
], [Command: sudo kbdbacklight
]. Click on Apply.
Click on the Disabled label and set the keyboard shortcut key or combination.
There should be available other possible solutions based on the data and functionalities of the commands as lsusb
, xinput
, evtest
, acpi_listen
(apcid
), etc. Here are few references that could provide useful ideas:
example txt
just like this... – Zuzia Feb 05 '18 at 21:26