How to run a script with the ability to set all open terminal instances at home directory, using Debian 9.
Asked
Active
Viewed 453 times
0
-
Each terminal would have to run the script... or you could paste a `cd` command to each window... or do you want all new terminals to automatically change to this specific directory upon opening? – Xen2050 Jan 17 '19 at 03:10
-
When I run the script it should put all terminal instances at /home EG. If I have 2 instances open: 1. at /etc and 2.at /bin When I run the script it should put the instance 1. at /home and the instance 2. at /home too. – Carlos Jan 17 '19 at 04:12
-
I'm not sure if that can be done... like first find all terminals/konsoles (or all interactive bashes), then send a signal or something to run a command. Or maybe find all konsole windows, and paste in a command might be easier, but what if the terminal is already running something, or has a command line being edited... interesting. But, maybe just going into each terminal and typing `cd` + ENTER is easiest (plain cd changes to my home, I think that's a default behaviour) – Xen2050 Jan 17 '19 at 05:01
-
@Xen2050 sure it can, konsole is quite programmable via dbus. There's a runCommand() method that can be performed on a session, see my answer. – Perl Ancar Jan 17 '19 at 07:57
1 Answers
4
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.

Perl Ancar
- 580
- 3
- 10
-
1Interesting, is there some way to list all the available methods/commands ex. org.kde.konsole.Session.runCommand or for other desktops, XFCE, etc? Or just run `qdbus` and see what's there? Or a webpage that lists them + commands? K seems to have [some docs](https://techbase.kde.org/Development/Tutorials/D-Bus/Introduction) and [this about konsole](https://docs.kde.org/trunk5/en/applications/konsole/scripting.html) – Xen2050 Jan 17 '19 at 22:58
-
Found qdbusviewer (in Debian/Ubuntu's qt4-dev-tools package), and [a page mentioning it](https://www.ics.com/blog/some-lesser-known-qt-tools-and-commands-part-2), and the dry [Qt D-Bus Documentation](http://doc.qt.io/qt-5/qtdbus-index.html), or [Control Your Linux Desktop with D-Bus on LinuxJournal.com](https://www.linuxjournal.com/article/10455), looks application specific – Xen2050 Jan 17 '19 at 23:31
-
-