3

I am try to modify my keyboard shortcuts using kwriteconfig5

The default value in ~/.config/kglobalshortcutsrc to lock the screen is

Lock Session=Meta+L\tCtrl+Alt+L\tScreensaver,Meta+L\tCtrl+Alt+L\tScreensaver,Lock Session

This maps to this in the System Settings -> Shortcuts - Session Management

Lock Session Shortcut

The format of the file seems to be :

  • "Shortcut name="
  • each option separated by \t
  • ","
  • each option repeated again to indicate that it is ticked
  • any option missing in the second set indicates not ticked
  • ","
  • "Shortcut name"

I can set the row in the file to empty with

kwriteconfig5 --file kglobalshortcutsrc --group ksmserver --key "Lock Session" ""

So in order to remove the Ctrl+Alt+L I tried:

kwriteconfig5 --file kglobalshortcutsrc --group ksmserver --key "Lock Session"  "Meta+L\tCtrl+Alt+L\tScreensaver,Meta+L\tScreensaver,Lock Session"

However, the \t in the final option appears in the file as \\t.

I have used several combinations of escaping and single/double quotes and it doesn't make a difference so it doesn't appear to be a normal escaping process.

The second issue is that even after changing the file, the shortcuts don't seem to stick in the System Settings.

One of the following appears to make the settings change:

qdbus org.kde.keyboard /modules/khotkeys reread_configuration
kquitapp5 kglobalaccel && sleep 2s && kglobalaccel5 &

However, I'm not 100% sure which one was doing it and what the real difference is between the two.

I can't find any documentation on how to do use kwriteconfig5 correctly.

Does anyone know the correct way to do this and has actually tested it out and got it to work?

2 Answers2

1

Issuing

kquitapp5 kglobalaccel && sleep 2s && kglobalaccel5 &

works fine for me, at least for kglobalshortcutsrc file. You just need to reopen settings window afterwards to see the change.

As for \\t issue: I'm using following sed command. Hope it helps someone:

sed -i '/Lock Session/s/\\\\t/\\t/g' ~/.config/kglobalshortcutsrc
  • -i is for edit in-place
  • /Lock Session/ finds the proper line to edit and
  • s/\\\\t/\\t/g changes all occurences of \\t into \t for that line.
gerhard d.
  • 2,188
  • For a more general solution, sed -i 's/\\\\t/\\t/' ~/.config/kglobalshortcutsrc seems to work fine. I took a backup before running it and the only thing that got changed was the bad double slash, so if one has more values with tabs to set, it should be more convenient. – Rafał G. Jun 09 '23 at 11:32
0

Did you try "...\\t..."?

Because you seem to be trying to write the characters \ and t in there. "\t" (with double quotes) is a single, actual tab character that you wouldn't want to supply kwriteconfig5 with.

  • Looks like there's a bug in kwriteconfig5. Whether you use "\\t" or "\t" as a part of the value, you still end up with a double slash getting saved. So the sed command posted by MrSegFaulty seems to be the only way to fix it at the moment. – Rafał G. Jun 09 '23 at 11:27