bashdebiankonsole

How to go home directory for all Konsole tabs open from bash script?


How to run a script with the ability to set all open terminal instances at home directory, using Debian 9.


Solution

  • This is can be done via DBUS, e.g.:

    for service in `qdbus | grep org.kde.konsole-`; do 
        for session in `qdbus $service | grep ^/Sessions/`; do
            qdbus $service $session org.kde.konsole.Session.runCommand "cd"
        done
    done
    

    This will find all "services" (Konsole processes), then find all sessions for each service, then send the command/characters "cd" to all those sessions.

    If you want to send only to a specific konsole process, you'll need to replace the first for loop.

    Also of note, this will work even when the session is running ssh to a remote server. All runCommand() method does is send characters to the session. But this also means the session needs to be having a shell prompt ready to accept a command, and not in the middle of running some other command.