anton-yarchuk
1/31/2020 - 12:59 PM

activity-switcher.sh

#!/bin/bash

function switchBrowserTo() {
    kwriteconfig5 --file ~/.config/kdeglobals --group General --key BrowserApplication "$1"
}

function applyChanges() {
    case "$1" in
    "Private")
        switchBrowserTo firefox.desktop
        ;;
    "Work")
        switchBrowserTo google-chrome.desktop
        ;;
    *) ;;
    esac
    
    echo "Switched to $1"
}

export DISPLAY=:0
dbus-monitor "type='signal',sender='org.kde.ActivityManager',interface='org.kde.ActivityManager.Activities',member='CurrentActivityChanged'" |
    while read -r line; do
        if [[ $line == signal* ]]; then
            currentActivityName=$(qdbus org.kde.ActivityManager /ActivityManager/Activities ActivityName $(qdbus org.kde.ActivityManager /ActivityManager/Activities CurrentActivity))
            applyChanges $currentActivityName
        fi
    done