0

I've been trying to figure out how to set a short cut to launch a new tab, with a specific profile, but I can't seem to find an option. Effectively I want to emulate the highlighted Menu option below: enter image description here

I can set shortcuts to Profiles in the Manage Profiles Pane, however, that changes the active tab's profile; not what I want (and in this case doesn't change the environment to Powershell). I can launch a new tab with a shortcut, but that uses the Default profile.

Nothing in the Configure Shortcuts screen shouts out that it will do this, and a search of "Konsole open new tab with profile shortcut" drew me to questions like Pressing opens a new tab in Konsole, Is there a keyboard shortcut to open a new Konsole tab? and Switch profile in Konsole from command line?; none of which address what I'm trying to achieve.

Can you actually set a shortcut for launching a new tab for a specific profile in Konsole?

  • Please run qdbus $KONSOLE_DBUS_SERVICE $KONSOLE_DBUS_WINDOW newSession in konsole and tell me if that opens a new tab. – danzel Mar 7 at 14:14
  • It does, @danzel . – Larnu Mar 7 at 14:14
1

TLDR

  • Disable "Run all Konsole windows in a single process" in konsole settings
  • install xdotool
  • Create a global shortcut with the follwing command, replacing [profile_name] with your profile's name:
qdbus org.kde.konsole-$(xdotool getwindowpid $(xdotool search --class "konsole" | tail -1)) /Windows/1 newSession "[profile_name]"; xdotool windowactivate $(xdotool search --class "konsole" | tail -1)

There doesn't seem to be a dedicated shortcut for this, and as this post suggests, the default behaviour seems to have changed in recent versions.

However, there is a workaround. As explained here, you can open a new session (=tab) by sending a qdbus command. The problem with this is that you need to run that command in a shell inside the konsole window, otherwise the environment variables will not be set. Now you could bind the following command to a keyboard shortcut in bash using bind:

qdbus $KONSOLE_DBUS_SERVICE $KONSOLE_DBUS_WINDOW newSession "[profile_name]"

...but using bind is not really user friendly and especially not shell independent. Alternatively, you can specify an alias if that is acceptable.

If you want to have a keyboard shortcut that is independent from the shell you are currently using, you'll need to use a global shortcut and inevitably lose the environment variables.

Using a global keyboard shortcut

The process depends on the "Run all Konsole windows in a single process" setting in "Settings -> Configure Konsole".

All windows in one process

If that is enabled, there will be one qdbus service called org.kde.konsole and each window will be an object Windows/1, Windows/2 etc. So if you only use one konsole window, the following command would be sufficient for a global keyboard shortcut:

qdbus org.kde.konsole Windows/1 newSession "[profile_name]"

One process for each window

If konsole is configured to spawn a new process for each window, you'll have some additional options. In that case, there will be one qdbus service for each window called org.kde.konsole-[process_id], each with only one object Windows/1.

To retrieve the id of the process owning the konsole window, we can use xdotool. In each of the following examples, replace [profile_name] with your profile's name:

open new tab in active konsole window

qdbus org.kde.konsole-$(xdotool getactivewindow getwindowpid) /Windows/1 newSession "[profile_name]"

open new tab in most recently used (or active) konsole window

qdbus org.kde.konsole-$(xdotool getwindowpid $(xdotool search --class "konsole" | tail -1)) /Windows/1 newSession "[profile_name]"

open new tab in most recently used (or active) konsole window and bring it to front

qdbus org.kde.konsole-$(xdotool getwindowpid $(xdotool search --class "konsole" | tail -1)) /Windows/1 newSession "[profile_name]"; xdotool windowactivate $(xdotool search --class "konsole" | tail -1)
| improve this answer | |
  • Thanks danzel for this, won't get a chance to try this out till the new week; though I was hoping that it was a little more "built in". Like yourself, though, I had noticed that the behaviour has changed over the years; surprised that just didn't leave the option for both. – Larnu Mar 7 at 21:37

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.