Last Updated: July 18, 2017
·
5.491K
· sachanski

Yakuake scripting

After getting tired of launching the same 5 sessions every time I have to restart Yakuake I started looking for an automatic solution and came across this post. It turns out DCOP is now obsolete and replaced with D-Bus. Long story short - here is a pretty handy script that can start Yakuake with a number of sessions already doing stuff:

INITIAL_ID=`qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.activeSessionId`
function addSession {
    SESSION_ID=`qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.addSession`
    qdbus org.kde.yakuake /yakuake/tabs setTabTitle $SESSION_ID "$1"
    if [ ! -z "$2" ]; then
        qdbus org.kde.yakuake /yakuake/sessions runCommandInTerminal $SESSION_ID "$2"
    fi
}

 addSession "Nodejs server" "cd /home/node-server/src && node server.js"
 addSession "Grunt Server" "cd /home/grunt-server && grunt"
 addSession "Top" "top"

 qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.removeSession $INITIAL_ID

First I am saving the id of the currently opened session in order to close it after everything is done. Then I am opening three sessions in Yakuake:

  • The first will launch a node js server located in /home/node-server/src with the title Nodejs server

  • The second will launch a grunt server located in /home/grunt-server with the title Grunt Server

  • The third will start monitoring the top CPU processes in a session with title Top

So basically if you need an additional session all you need to do is call addSession with first argument - the title, and optionally a second argument - a shell command that will be executed in the new session.

There are a lot more stuff you can do with the IPC interface provided by qdbus. You can check those out by simply typing qdbus org.kde.yakuake and the autocomplete shows the rest. There are a couple of scripts I found which could also be helpful

  1. aplatanado/yakuake-session

  2. p5-yakuake-sessions

Hope this helps!