There may be some sort of solution that can be put together, but it would require running scripts and the first thing I noticed is that KTimeTracker doesn’t seem to have command-line actions to start/pause/stop tracking.
From a quick search online, it looks like there are some CLI programs like Timewarrior or timetrace, or there’s a GTK/GNOME program called Hamster which all seem to have some degree of control via command-line and could potentially work with being controlled by scripts.
With a time tracking app selected, one solution would be to use Pytivity, which may be a quicker solution than the below, as it allows you to configure commands to run when activity states change.
Another solution would be to manually setup scripts (.desktop
files will also work apparently, but I’ll keep referring to scripts) that kactivitymanagerd
will run. To do this you need to place the scripts under ~/.local/share/kactivitymanagerd/activities/{activity_uuid}/{state}/
, where {activity_uuid}
is the UUID for the activity and {state}
is one of: activated
, deactivated
, started
or stopped
. You would probably need to create the activities
folder under ~/.local/share/kactivitymanagerd/
.
To find the UUID’s, you can get them via dbus with:
qdbus --literal org.kde.ActivityManager /ActivityManager/Activities org.kde.ActivityManager.Activities.ListActivitiesWithInformation
The output should look something like [Argument: a(ssssi) {[Argument: (ssssi) "2b51e992-14be-4e3b-a090-89ffe2d0d5a0", "Default", "", "", 2], [Argument: (ssssi) "fb836882-de8f-44ab-a5ea-807442eb24a0", "Test", "", "activities", 2]}]
which has two activities, one named Default
and one named Test
.
For the above example output, you’d create folders for each UUID, so for the Default
activity, you’d have the folder ~/.local/share/kactivitymanagerd/activities/2b51e992-14be-4e3b-a090-89ffe2d0d5a0/
. Under each UUID folder, you can then create the relevant state, so if you want to run something when you switch to an activity you would create a folder called activated
and then for when you switch away from that workspace you’d want a folder called deactivated
.
If you put scripts (that are executable of course) under the respective directories, they should run when you switch to/away from them. If you can find something that you can run a command to start/pause/stop tracking the time, you could use that.