6

Can a command be set to run when switching to a specific virtual desktop (or an activity) in KDE environment?

I want to run a command for a desktop (e.g. desktop2) so that when I switch to that desktop, the keyboard language layout will change to English US automatically.

2
  • 2
    This is an great concept! I can't believe there isn't a plasmoid for this, especially for your example use case. You should consider revising the question to make it as clear and broadly applicable as possible in order to get the most attention for this question. In the meanwhile I'm trying to figure out how to write my own plasmoid that can detect the activity space I'm using.
    – virtualxtc
    Jan 2, 2014 at 23:30
  • 1
    The closest I've found is the STDOUT plasmoid that can be found when choosing to "get new widgets" after right clicking on the task bar and choosing 'pannel options' - 'add widgets'. However it seems to always execute no matter what activity space you are currently in.
    – virtualxtc
    Jan 2, 2014 at 23:33

3 Answers 3

3

You can change to virtual desktop two using the following command line argument:

wmctrl -s 2

Thus executing

wmctrl -s 2 && setxkbmap en

should switch your to desktop 2 and change your language to english as suggested in your example.

You can use a keybinding program like autokey, or KDE custom shortcuts to set a keybinding for the above command. Alternatively, you can save the above command to a text file ending in .sh, and then make the file executable to have a clickable script that will switch desktops and change languages for you.

should switch your to desktop 2 and change your language to english as suggested in your example.


Switching activities is a bit more lengthy command.

Going to go to the next activity is simple enough using:

qdbus org.kde.kglobalaccel /component/plasma_desktop invokeShortcut "Next Activity"

However to switch to a specific activity, you must fist know it's ID which can be obtained by:

qdbus org.kde.kactivitymanagerd /ActivityManager/Activities ListActivities

Once you know the activity id you can switch to that activity via:

qdbus org.kde.kactivitymanagerd /ActivityManager/Activities SetCurrentActivity activity-key-in-previous-step

then couple that with the '&& setxkbmap en' command as shown above when switching virtual desktops to have activity switching coupled with a language change.


Also of note:

export LC_ALL=C

will change the system language to english

5
  • If you are a decent script writer you can use wmctrl -d to create a desktop aware script that monitors the current desktop and automatically switches it for you. I'm uncertain how to do this for "activities"
    – virtualxtc
    Jan 3, 2014 at 0:20
  • I can send a key combination to change the language in command-line. But I don't know if there's any command for changing language layout in command-line (export LC_ALL=C doesn't work for me). Jan 3, 2014 at 0:24
  • Thanks but, as I have said times (e.g.) the bug commented here; has made qdbus useless for me (probably until KDE 4 sunsets). setxkbmap is better, yet it seems to have a locking nature. Jan 3, 2014 at 6:44
  • isn't your complaint about toggling solved by creating a shell script as in minerz029 example in your other question askubuntu.com/questions/399248/a-command-for-showing-desktop and shouldn't global keybindings solve the issue with klipper?
    – virtualxtc
    Jan 3, 2014 at 6:53
  • wmctrl describes it sef as an "X Window Manager: -- I'm thinking it won't work for Wayland
    – will
    Jun 16, 2023 at 17:14
2
  • Devil's Pie 2 lets you launch a script when that Window #n is created, which is not quite what you wanted, but simple;
  • you can use Autokey to run a script which switches the window then changes the language, and launch another script to revert to the original settings, all by hotkey, or
  • there's also a GUI-aware Scripting tool called Sikuli you might find interesting.
0
2

Thanks to virtualxtc's answer above and don_crissti's answer. To change layout download this zip file linked in this page. Extract it to a folder in home folder. Then run terminal inside the folder and run these commands:

cmake CMakeLists.txt
make CMakeLists.txt
cmake CMakeLists.txt
sudo make install CMakeLists.txt

(you may need to install make and cmake)

then run this command to switch to English:

xkb-switch -s us

and a combination can be

wmctrl -s 1 && xkb-switch -s us

which one can assign a hotkey to it to switch to desktop2 and English.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .