Yesterday I was quite happy about my shortcut to launch an internet search that I couldn’t help but play around a little more with the scripting abilities of dbus.

When Activites were first introduced in KDE I was quickly missing shortcuts to change Activites quickly when I have my fingers on the keyboard. I stumbled across a dbus method to assign shortcuts to a specific activity . It actually works well but my problem is that I have way to many activities than I’m willing to manually create shortcuts for and most of the time I only have 3 or 4 of them open anyways. I noticed in a video of a Ubuntu Unity that they introduced some numeric shortcuts to open programs; why not try something similar with Activities.

Like the last hack we again need a script file which will be called by a global shortcut.

Safe the script somewhere in your homedirectory and make it executable.

#!/bin/bash #shortcut = Meta + $Counter COUNTER=1 #read existing Activities into array ActivityList=( `qdbus org.kde.kactivitymanagerd /ActivityManager ListActivities |tr '

' ' '` ) #save Active Activities in array and add shortcut to name for i in "${ActivityList[@]}"; do if [ `qdbus org.kde.kactivitymanagerd /ActivityManager ActivityState $i` = "2" ]; then #store activity id ActiveActivityList[$COUNTER]=$i #Activate selected Activity for COUNTER if [ $1 = $COUNTER ]; then qdbus org.kde.kactivitymanagerd /ActivityManager SetCurrentActivity ${ActiveActivityList[$1]} fi #get current activity name and delete previous shortcut ActivityName="`qdbus org.kde.kactivitymanagerd /ActivityManager ActivityName $i |sed -e 's/[ ](.*)//'`" #$echo $ActivityName #add shortcut indicator to activity name qdbus org.kde.kactivitymanagerd /ActivityManager SetActivityName $i "${ActivityName} (${COUNTER})" #echo `qdbus org.kde.kactivitymanagerd /ActivityManager ActivityName $i` let COUNTER+=1 fi done

Next we create some Global Shortcuts calling this script with a identifier 1, 2, 3 etc as an argument. Notice the 3 behind the script’s path for which I have assigned the Trigger Meta+3, 4 for Meta+4 etc. After you have enabled the Global Shortcuts, that’s basically it. After adding or removing an Activity you might have to invoke the script for the shortcuts to update. A word of caution: The script will read the name of your active Activities and either delete the previous shortcut indicator and add the current one. Therefor you shouldn’t use brackets and only single words in your Activity names since I haven’t tested the regex extensivly and it might screw up your Activity names. This way of adding shortcuts probably makes most (only?) sense if the Activities and their shortcut names are visible. Here is a screenshot how i setup my desktop. Unfortunately the Activities are added to that panel in a somewhat unpredictable way which I haven’t entirly figured out yet so while the shortcuts are corret the numbers they are not consecutive.

=-=-=-=-=

Powered by Blogilo