1

This question exists for some other sony vaio laptop models (without answer); I haven't yet seen an answer for the sony vaio PCG-41217N laptop.

The suggestion to execute xset led off doesn't disable the backlight. Because this laptop is for work, I don't want to risk installing third-party software.

Looking at a previous asker's sony vaio work, my sudo dmidecode -s system-product-name gives VPCSB1AHJ. I do have /sys/devices/platform/sony-laptop/kbd_backlight and kbd_backlight_timeout files. Both are 4.1 kB with only the text '-1' when opened in gedit.

1

I was able to turn off my keyboard backlight by changing the value of the read-only text file "kbd_backlight" to 0 (originally -1) after opening it in gedit with root access via sudo gedit /sys/devices/platform/sony-laptop/kbd_backlight in Terminal.

Please be advised that using sudo to open gedit is problematic, with multiple recommendations on this site to use gksudo instead to properly manage file ownership between user and root. When I executed sudo gedit, I received multiple warnings in Terminal.

  • Nice. If you wish I could write an answer how to create keyboard shortcut that changes this value, using script that is executed by sudo without password. – pa4080 Dec 20 '17 at 10:24
  • Yes, please: I would like to assign it to an unused key (maybe even replace the key that disables my trackpad...), since the keyboard backlight may sometimes be useful. I stored a memo regarding how to hopefully re-enable the setting, since I lack such a keyboard shortcut. – DBinJP Dec 20 '17 at 10:33
  • What is the version of your Ubuntu? – pa4080 Dec 20 '17 at 10:39
  • 16.04 LTS, 64-bit – DBinJP Dec 20 '17 at 11:00
  • To recover from the issue caused by sudo gedit restore the ownership permissions to the content of your user's home directory: sudo chown -R $USER:$USER $HOME. Next time use: sudo -H gedit or sudo -i gedit or gksu gedit. But the better idea is to gain ability to work with nano or some other terminal based text editor. – pa4080 Dec 20 '17 at 15:19
1

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 SettingsKeyboardShortcuts (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:

1

All works thanks!

I adopted the script from the other answer for my needs. Now my touchpad works. With little changes, that script works for my keyboard backlight and for my touchpad. Just replace KBDBACKLIGHT with TOUCHPAD - look the original script above.

I'm using Ubuntu 17.10 with Gnome.

#!/bin/sh
TOUCHPAD="/sys/devices/platform/sony-laptop/touchpad"
read VALUE < "$TOUCHPAD"  
if   [ "${VALUE}" -eq '0' ]; then echo '1' > "$TOUCHPAD"; notify-send "Touchpad ON" 
elif [ "${VALUE}" -eq '1' ]; then echo '0' > "$TOUCHPAD"; notify-send "Touchpad OFF"
else echo "Something went wrong."; notify-send "Something went wrong."
fi

Now on my Sony Vaio the custom shortcut ctrl+win+* works as on/off switch of the keyboard backlight and ctrl+win+F1 disable and enable the touchpad. Please pay attention of the VALUEs - my laptop's on/off values are 1 and 0 not like in the original script 0 and -1. (edit these numbers if not work on your laptop).

Cheers :)

  • Could you please try to reformat the text of your answer ? It seems to be missing some punctuation, which makes it hard to read. Also, don't thank people in an answer, that's what comments are for. – Robert Riedl Feb 5 '18 at 18:29
  • Dear Mr. Robert i dont know how to edit post for super look colorfull script like Yours i try all but not work in block. Even if i try just bold font till i have example txt stars add to code. Sorry i dont know what i doing wrong. In that post all looks normal in <code>**example txt**</code> just like this... – Zuzia Feb 5 '18 at 21:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.