1

I want to periodically run a script (with cron, for example) which will parse received notifications (last N notifications), and, if a notification contains the text I need, the script should run an external command.

How can I accomplish that in KDE Plasma 5?


For example:
using notify-send command to create and send notifications, I can send 2 notifications with:
notify-send test12345
notify-send "VERY_IMPORTANT_MSG!!!!!!"

Now there are 2 unread notification in the system tray. I want to parse them, and if they contain VERY_IMPORTANT_MSG!!!!, some external command should run.

I know about the notification feature Configure notification events and actions -> System Services -> Configure events -> Run command
but I can't use it since I need to parse various notification from multiple sources.

3
  • Welcome to SuperUser! Please note that this site is not a script-writing service. If you have begun writing a script for this already, can you please show us what you have so far? If you have not yet, please at least share the research you have done, but also, begin writing a script based on that research. Use the EDIT button to add this information, as you have it, to this question. Commented Jun 25 at 14:15
  • the script itself is not a problem, I need a way to get the notifications text Commented Jun 25 at 14:21
  • Ok, please note that your original question didn't specify that at all, but only said "I want to run a script that does X. How can I accomplish that?" Your edit improves things, but please consider editing the ENTIRE question more thoroughly to make it clear, from the outset and then throughout, specifically what you are trying to solve. Commented Jun 25 at 14:24

1 Answer 1

0

This script monitors notification server messages, and runs mpv player if a message contains the text in SEARCH_FOR variable.

#!/usr/bin/env bash

SEARCH_FOR='VERY_IMPORTANT_MSG'  

dbus-monitor "interface=org.freedesktop.Notifications" |
grep "$SEARCH_FOR" --line-buffered |
while read found_line; do
  echo "$found_line" 
  mpv "${HOME}/sounds/alarm.mp3" # replace with your command
done

Works in KDE Plasma 5.27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .