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

How can I run scripts when I switch to or from an activity?

Tags: plasma, activities, scripts, activitymanager plasma, activities, scripts, activitymanager plasma, activities, scripts, activitymanager
(comma "," separated)
bugzy
Registered Member
Posts
5
Karma
0
How can I run specific scripts whenever I switch to an activity or away from it.
Suppose I have the following activities:
  • workplace
  • media

My goal is to be able to accomplish something like the following:
* On switch to workplace 1 activity
- run ScriptA, which tells plasma-nm to connect to workplace 1 VPN connection and opens konsole with several tabs that contain ssh connections that are available only over vpn
* On switch away from workplace 1 activity
- run ScriptB, which closes any konsole windows in this activity and tells plasma-nm to close connection to workplace 1 VPN

I have "ScriptA" done, and I tried to get the workflow above working based on the information at https://www.reddit.com/r/kde/comments/81p77h/activity_for_memory_cpu_saving/dv5or9g Reproduced below:
The Consumer is the class you might use if you wanted ti make a C++ service that does this (or you could make a kactivitymanagerd plugin).
If you want to do it via shell scripting, there is an undocumented feature of the activitymanager daemon to run scripts/applications on certain activity events. If you put a script (chomd +x) into ~/.local/share/kactivitymanagerd/activities/ACTIVITY_UUID/started, it will be executed when the activity starts. Other supported events are stopped, activated and deactivated.
If you manage to integrate activities with lxc or docker, please write a guide somewhere - this would be a really cool thing to have for people who want proper containerized session support.

First, the information is a bit unclear since I do not know if "started" should be a folder or the name of the script file that will be executed. In either case, however, I am unable to get my script to run either when switching to the relevant activity or starting and stopping it. Any help or guidance on this will be greatly appreciated.
User avatar
Akito
Registered Member
Posts
6
Karma
0
Did you find a solution? I am interested in this topic, to make stuff like what you tried to achieve work.
leodream
Registered Member
Posts
1
Karma
0
I also came across similar requirement and found that there are multiple methods
    - Put a shell script or ".desktop" file into the "~/.local/share/kactivitymanagerd/activities/<ACTIVITY_UUID>/<state>" folder.
      - the <state> can be "started", "stopped", "activated", "deactivated". The later 2 should be triggered when switching to/from the target activity
      - the <activity_uuid> can be acquired via
      Code: Select all
      qdbus org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.CurrentActivity
    - Associate the script to the activities via "Power Management -> Activities Power Settings -> Run script"


Bookmarks



Who is online

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