qusal/salt/dom0/files/autostart-scripts/kde-activity-changed-notifier
Ben Grande 224312ed42
feat: enable all optional shellcheck validations
Make shell a little bit safer with:

- add-default-case
- check-extra-masked-returns
- check-set-e-suppressed
- quote-safe-variables
- check-unassigned-uppercase

Although there are some stylistic decisions for uniformity:

- avoid-nullary-conditions
- deprecated-which
- require-variable-braces
2024-07-10 14:36:05 +02:00

40 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# SPDX-FileCopyrightText: 2018 Oded Arbel <https://geek.co.li>
# SPDX-FileCopyrightText: 2023 Benjamin Grande M. S. <ben.grande.b@gmail.com>
#
# SPDX-License-Identifier: MIT
## Credits: https://geek.co.il/2018/07/30/script-day-different-default-browser-per-kde-activity
set -eu
if ! command -v notify-send >/dev/null &&
! command -v kdialog >/dev/null; then
exit 1
fi
command -v qdbus >/dev/null || exit 1
case "${XDG_SESSION_DESKTOP:-}" in
KDE|plasma) ;;
*) exit 1;;
esac
service="org.kde.ActivityManager"
interface="${service}.Activities"
path="/ActivityManager/Activities"
signal="CurrentActivityChanged"
dbus-monitor --profile \
"type=signal,path=${path},interface=${interface},member=${signal}" | \
while read -r _ _ _ _ _ path interface member; do
test "${member}" = "${signal}" || continue
id="$(qdbus "${service}" "${path}" "${interface}.CurrentActivity")"
name="$(qdbus "${service}" "${path}" "${interface}.ActivityName" "${id}")"
if command -v kdialog >/dev/null; then
kdialog --title "Activity: ${name}" --passivepopup "Switched Activities" 3
elif command -v notify-send >/dev/null; then
notify-send -u normal -t 3000 "Activity: ${name}" "Switched activities"
fi
done