Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #params: title force
- function konsole_activate {
- #this stopped working at some point: xdotool search --class konsole windowactivate
- xdotool windowactivate $((`wmctrl -l |grep " Konsole$" |cut -d' ' -f1`))
- }
- function konsole_getTitles { #call getSessions first
- konsole_sessions=`dbus-send --dest=org.kde.konsole --type=method_call --print-reply /Windows/1 org.kde.konsole.Window.sessionList |grep string |cut -d\" -f2`
- konsole_titles=""
- for i in $konsole_sessions ; do
- title=`dbus-send --dest=org.kde.konsole --type=method_call --print-reply=literal /Sessions/$i org.kde.konsole.Session.title int32:1`
- konsole_titles=${konsole_titles}$i:${title##* }"\n"
- done
- }
- function konsole_getSessionByTitle {
- set -o pipefail
- sessionNumber=`echo -e "$konsole_titles" |grep :$1$ |head -1 | cut -d: -f1 || echo 0`
- return $sessionNumber
- }
- function konsole_switchToSession {
- while [ $1 -ne `dbus-send --dest=org.kde.konsole --type=method_call --print-reply=literal /Windows/1 org.kde.konsole.Window.currentSession |awk '{print $2}'` ]; do
- dbus-send --dest=org.kde.konsole --type=method_call --print-reply=literal /Windows/1 org.kde.konsole.Window.nextSession
- sleep .1
- done
- }
- konsole_activate
- #if force just exit
- [ "$2" == "1" ] && exit 0
- konsole_getTitles
- konsole_getSessionByTitle $1 || konsole_switchToSession $sessionNumber
- exit $sessionNumber
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement