This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Automatically assign numerical shortcuts to your Activities

Tags: None
(comma "," separated)
tomsdale
Registered Member
Posts
14
Karma
0
OS
Hi,

I have been using this http://hanschen.org/2011/05/20/switch-to-specific-activities-with-keyboard-shortcuts/ method for some time now to assign shortcuts to my activities. Since I had too many and couldn't assign shortcuts to each of them I came up with a small script using qdbus to automatically assign numerical shortcuts to the active ones. I saw something similar in a video about Ubuntu Unity. This makes most sense on a desktop which has the Activity panel visible since they will change when you close/open activities. Unfortunately they are sometimes out of sequence but it's only a hack or proof of concept.

Here is what it looks on my Desktop with the activity panel. The numbers in brackets indicate the shortcut e.G. Meta+1, Meta+2 etc.
(sry too big for forum) http://i.imgur.com/2MN4H.png

First we need an executable bash script saved on your home dir:

Code: Select all
#!/bin/bash

#shortcut =  Meta + $Counter
COUNTER=1

#read existing Activities into array
ActivityList=( `qdbus org.kde.kactivitymanagerd /ActivityManager ListActivities |tr '\n' ' '` )

#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 need to assign global shortcuts to launch this script and pass the number of the shortcut to the script when it's pressed.

You can add new global shortcuts under Systemsettings->Shortcuts And Gestures->Custom Shortcuts. at the bottom click edit -> new -> Global Shortcut

Image

I actually exported that so you can import it yourself but you don't seem to be able to attach files to posts.

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.

Please note not to use () in your activities or the regex might screw up with the name of your activities. I have been using this for a couple of days and apart from the order of the activities I think it's pretty usable for me.

If you find some improvements or have some comments please let me know.

This is a repost from my blog where there is some more detail if you're interested.
http://yadigaga.wordpress.com/2011/07/0 ... es-in-kde/
User avatar
Hans
Administrator
Posts
3304
Karma
24
OS
Great to see that you posted it here as well, thank you for this tip!


Problem solved? Please click on "Accept this answer" below the post with the best answer to mark your topic as solved.

10 things you might want to do in KDE | Open menu with Super key | Mouse shortcuts
labrador training
Registered Member
Posts
1
Karma
0
OS
Hey Tomsdale,

I have been using your idea of automatically assigning numerical shortcuts to my activities and found it quite useful. The problem with the order of the activities is a small price to pay for the benefits of this concept.
tomsdale
Registered Member
Posts
14
Karma
0
OS
>The problem with the order of the activities is a small price to pay for the benefits of this concept.

Glad you like it. I actually had a look into the activity bar applet sourcecode and this line caught my attention:


Code: Select all
void ActivityBar::insertActivity(const QString &id)
{
    //assumption: activities are always added at the end of the list
    //kDebug() << "activity" << id;
    m_activities.append(id);
    m_tabBar->addTab(QString()); //name will be added on dataUpdated
}


I think it always adds the activity to the end of the list while the qdbus command returns a different sorting from the command line, thus the out of sequence result.


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot]