Hello, how do i set a shortcut to focus a specific window? I am trying to set a shortcut that can focus on a window and take me to the correct desktop. Do i need to make a kwin script to do this or can i use some of the built in features? im on plasma 6.5.5
You can use the tool “kdotool” it can do that,
but you will have to make a smal bash script.
Then add the bash script to the shortcuts panel.
The bash script may be a simple as:
#!/usr/bin/env bash
# Focus the first window whose title or class contains "firefox"
# and switch to the desktop it resides on, keeping everything in variables.
# Find the window ID (first match)
WIN_ID=$(kdotool search --name --class --limit 1 "firefox")
# If no window was found, exit silently
[[ -z "$WIN_ID" ]] && exit 0
# Get the desktop number for that window
DESKTOP=$(kdotool get_desktop_for_window "$WIN_ID")
# Switch to that desktop
kdotool set_desktop "$DESKTOP"
# Activate (focus) the window
kdotool windowactivate "$WIN_ID"
wow thanks! works great, didnt know about kdotool. im having a slight issue tho it only launches from the terminal, not sure why it does not launch when setting the script as a kde shortcut quite odd.
ok i managed to fix the issue by moving the kdotool file to the bin folder and having the script launched like this
konsole -e “/path/to/the/script.sh”