如何从 bash 脚本打开所有 Konsole 选项卡的主目录?

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

如何使用 Debian 9 运行 一个能够在主目录中设置所有打开的终端实例的脚本。

这可以通过 DBUS 完成,例如:

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

这将找到所有 "services"(Konsole 进程),然后找到每个服务的所有会话,然后将 command/characters "cd" 发送到所有这些会话。

如果您只想发送到特定的 konsole 进程,则需要替换第一个 for 循环。

另外请注意,即使会话是 运行 ssh 到远程服务器,这也会起作用。所有 runCommand() 方法所做的就是将字符发送到会话。但这也意味着会话需要有一个 shell 提示准备好接受命令,而不是在 运行 其他命令的中间。