Xfce Forum

Sub domains
 

You are not logged in.

#1 2023-04-26 16:22:06

aalbani
Member
Registered: 2023-03-30
Posts: 28

dunst plugin for the taskbar

Hello,
I use "dunst" as notification.
Is there a plugin for the taskbar, similar to xfce4-notifyd?

Offline

#2 2023-04-26 23:31:23

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: dunst plugin for the taskbar

I don't believe dunst comes packaged with a tray plugin. However, the awesome genmon plugin might be able to fit the bill for you.

What do you expect to see on the panel with a dunst notifier and what would you expect to see if you click the panel icon?


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2023-04-27 03:50:23

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

I would like to have a visual display of the messages in the taskbar when I missed the desktop message.
And a history would not be bad...

But if there is nothing, I can live with it.
Thanks

Offline

#4 2023-04-27 11:02:45

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: dunst plugin for the taskbar

You would be limited by what dunst exposes. Using "dunstctl count", you can get the following information:

  • Waiting = notification has arrived but not yet displayed (on standby or dunst is paused)

  • Displayed = number currently displayed on screen

  • History = number in your history file

"dunstctl history" will also dump a json file of your history which can then be processed by jq.

To give this a try to see if it works for you, create the following script and make it executable:

#!/bin/bash
# required dunst and jq

# max number of items to display in tooltip
ITEMSTODISPLAY=10

# get dunst outputs
COUNT=$(dunstctl count)
OUT=$(dunstctl history)

# process general stats
WAITING=$(echo "$COUNT" | grep "Waiting" | awk '{print $2}')
DISPLAYED=$(echo "$COUNT" | grep "displayed" | awk '{print $3}')
HISTORY=$(echo "$COUNT" | grep "History" | awk '{print $2}')

# clamp number of items to display in tooltip
[[ $HISTORY -ge $ITEMSTODISPLAY ]] && NUMITEMS=$ITEMSTODISPLAY || NUMITEMS=$HISTORY

# retrieve notification data
for (( c=0; c<$NUMITEMS; c++ ))
do
	MESSAGE[$c]=$(echo $OUT | jq ".data[][$c].message.data" | sed 's/\"//g')
	APPNAME[$c]=$(echo $OUT | jq ".data[][$c].appname.data" | sed 's/\"//g')
	ID[$c]=$(echo $OUT | jq ".data[][$c].id.data")
done

# do the genmon
echo "<txt>? $WAITING </txt>"
echo "<tool>"

echo -e "Waiting: $WAITING / Displayed: $DISPLAYED / History: $HISTORY"

for (( c=0; c<$NUMITEMS; c++ ))
do
	echo ""
	echo "[${ID[$c]}] App: ${APPNAME[$c]}"
	echo "${MESSAGE[$c]}" | sed 's/\\n/ - /g'
done

echo "</tool>"

exit 0

A few notes:

  • this script requires that jq is installed.

  • Edit the ITEMSTODISPLAY variable at the top of the script to indicate how many historical notifications you want dispalyed in the tooltip

  • Don't set the period to low as this will lead to a race conditions. 15 or 30 seconds would be best

  • When setting the genmon options :

    • Command = /path/to/script

    • label = unchecked

    • period = 30

    • Font = your choice


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2023-04-27 12:44:44

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

Thank you for the script.
But how do I use it?

Offline

#6 2023-04-27 13:37:57

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

Found it...
History is displayed, but the taskbar shows a question mark and the number zero.
Edit:
It also shows zero for new messages at Displayed and Waiting.

Last edited by aalbani (2023-04-27 15:11:10)

Offline

#7 2023-04-27 16:31:54

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: dunst plugin for the taskbar

aalbani wrote:

History is displayed, but the taskbar shows a question mark and the number zero.

The symbol didn't copy over properly in this bulletin board. Search google for "bubble unicode" or "bell unicode" for a text version of the symbol and copy it from there and paste it into the code. We can also use images or icons if thats easier.

Edit:
It also shows zero for new messages at Displayed and Waiting.

This is what I was referring to when I said "You would be limited by what dunst exposes". Dunst is exposing that information, meaning what it means to them, and thats all we have access to. To test the Waiting one, pause dunst:

dunstctl set-paused true

...and send a notification:

notify-send test test

Wait for the genmon cycle to expire and then the tooltip will show a value of 1.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#8 2023-04-27 17:05:36

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

Yes, that's fine.
Thank you very much...

Offline

#9 2023-04-27 17:46:03

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: dunst plugin for the taskbar

The more I look at it, the more the waiting and displayed don't make much sense.

We could change the plugin so that:
- it only processes history
- changes the coloroif the genmon string depending on whether there is history or not
- clears the history when the plugin is clicked

Let me know if you'd like the script tweaked like this.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#10 2023-04-28 02:06:41

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

yes you are right.
It would make sense to display the messages in total and then only a certain time. Waiting and Displayed are pointless.
If it is possible, an icon that changes when you have unread messages would not be bad.

Offline

#11 2023-04-28 02:38:37

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: dunst plugin for the taskbar

aalbani wrote:

If it is possible, an icon that changes when you have unread messages would not be bad.

AFAICT, dunst doesn't have the concept of "unread". Unless, you mean history.

Attached is a version of the script that:

  • only tracks history

  • if history exists, it colors the text red (otherwise white)

  • if you click the plugin, you will be offered the option to clear the history

  • history is still displayed in tooltip

This version doesn't use an image/icon yet. Let me know how it works and whether images/icons are still preferred, and if so, what do you expect to see if history exists and if history does not exist.

Note: this version requires the zenity package as well.

#!/bin/bash
# requires dunst, jq & zenity

# max number of items to display in tooltip
ITEMSTODISPLAY=10

# get dunst outputs
HISTORY=$(dunstctl count history)
OUT=$(dunstctl history)

# change the colour of the plugin depending on history
[[ $HISTORY -gt 0 ]] && COLOR=red || COLOR=white

# clamp number of items to display in tooltip
[[ $HISTORY -ge $ITEMSTODISPLAY ]] && NUMITEMS=$ITEMSTODISPLAY || NUMITEMS=$HISTORY

# retrieve notification data
for (( c=0; c<$NUMITEMS; c++ ))
do
	MESSAGE[$c]=$(echo $OUT | jq ".data[][$c].message.data" | sed 's/\"//g')
	APPNAME[$c]=$(echo $OUT | jq ".data[][$c].appname.data" | sed 's/\"//g')
	ID[$c]=$(echo $OUT | jq ".data[][$c].id.data")
done

# do the genmon
echo "<txt><span foreground='$COLOR'>? $HISTORY </span></txt>"
echo "<txtclick>sh -c 'zenity --question --title \"Delete dunst history\" --default-cancel && dunstctl history-clear'</txtclick>"
echo "<tool>Notification History:"
for (( c=0; c<$NUMITEMS; c++ ))
do
	echo ""
	echo "[${ID[$c]}] App: ${APPNAME[$c]}"
	echo "${MESSAGE[$c]}" | sed 's/\\n/ - /g'
done

echo "</tool>"

exit 0

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#12 2023-04-28 10:47:12

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

I find the display as a number quite good. Is it still possible to limit the time, so that the messages are emptied after a certain time?
And what do I do with the question mark?

Offline

#13 2023-04-28 11:06:56

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: dunst plugin for the taskbar

aalbani wrote:

I find the display as a number quite good.

And what do I do with the question mark?

If the number alone is fine, then delete the question mark from the script and it will only display the number on the panel.

Is it still possible to limit the time, so that the messages are emptied after a certain time?

Do you mean auto-delete the history? Wouldn't that go against the idea of showing the information so you can review it if you've missed it? By clicking on the plugin it will offer you the opportunity to delete the history. This way you can control when the delete event happens.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#14 2023-04-28 11:44:34

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

Yes it all fits like this.
Have you many many thanks

Offline

#15 2023-05-16 08:10:29

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

#!/bin/bash
# requires dunst, jq & zenity

# max number of items to display in tooltip
ITEMSTODISPLAY=5

# get dunst outputs
HISTORY=$(dunstctl count history)
OUT=$(dunstctl history)

# change the colour of the plugin depending on history
[[ $HISTORY -gt 0 ]] && COLOR=white || COLOR=white

# clamp number of items to display in tooltip
[[ $HISTORY -ge $ITEMSTODISPLAY ]] && NUMITEMS=$ITEMSTODISPLAY || NUMITEMS=$HISTORY

# retrieve notification data
for (( c=0; c<$NUMITEMS; c++ ))
do
	MESSAGE[$c]=$(echo $OUT | jq ".data[][$c].message.data" | sed 's/\"//g')
	APPNAME[$c]=$(echo $OUT | jq ".data[][$c].appname.data" | sed 's/\"//g')
	ID[$c]=$(echo $OUT | jq ".data[][$c].id.data")
done

# do the genmon
if [ $NUMITEMS == 0 ]; then
    echo "<txt><span foreground='$COLOR'>  </span></txt>"
else
    echo "<txt><span foreground='$COLOR'> <sup>$HISTORY</sup> </span></txt>"
fi
echo "<txtclick>sh -c 'zenity --question --title \"Delete dunst history\" --default-cancel && dunstctl history-clear'</txtclick>"
echo "<tool>Notification History:"
for (( c=0; c<$NUMITEMS; c++ ))
do
	echo ""
	echo "[${ID[$c]}] App: ${APPNAME[$c]}"
	echo "${MESSAGE[$c]}" | sed 's/\\n/ - /g'
done

echo "</tool>"

exit 0

The tooltip is empty from 2 messages...

Offline

#16 2023-05-16 10:03:16

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: dunst plugin for the taskbar

This code simply reads and processes the output from dunstctl. What do the two following commands return with this issue:

dunstctl count history
dunstctl history

If they both return nothing, then nothing will be displayed by the plugin.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#17 2023-05-16 10:24:35

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

dunstctl count history 
5
dunstctl history 
{
	"type" : "aa{sv}",
	"data" : [
		[
			{
				"body" : {
					"type" : "s",
					"data" : "Einrastende Tasten sind aktiviert"
				},
				"message" : {
					"type" : "s",
					"data" : "<b>Einrastende Tasten</b>\nEinrastende Tasten sind aktiviert"
				},
				"summary" : {
					"type" : "s",
					"data" : "Einrastende Tasten"
				},
				"appname" : {
					"type" : "s",
					"data" : "xfce4-settings-helper"
				},
				"category" : {
					"type" : "s",
					"data" : ""
				},
				"default_action_name" : {
					"type" : "s",
					"data" : "default"
				},
				"icon_path" : {
					"type" : "s",
					"data" : "/usr/share/icons/hicolor/scalable/status/keyboard.svg"
				},
				"id" : {
					"type" : "i",
					"data" : 6
				},
				"timestamp" : {
					"type" : "x",
					"data" : 14359015787
				},
				"timeout" : {
					"type" : "x",
					"data" : 2000000
				},
				"progress" : {
					"type" : "i",
					"data" : -1
				}
			},
			{
				"body" : {
					"type" : "s",
					"data" : "WILD"
				},
				"message" : {
					"type" : "s",
					"data" : "<b>LocoLea hat begonnen, zu streamen</b>\nWILD"
				},
				"summary" : {
					"type" : "s",
					"data" : "LocoLea hat begonnen, zu streamen"
				},
				"appname" : {
					"type" : "s",
					"data" : "Streamlink Twitch GUI"
				},
				"category" : {
					"type" : "s",
					"data" : ""
				},
				"default_action_name" : {
					"type" : "s",
					"data" : "default"
				},
				"icon_path" : {
					"type" : "s",
					"data" : "/tmp/.io.nwjs.jesyx6"
				},
				"id" : {
					"type" : "i",
					"data" : 5
				},
				"timestamp" : {
					"type" : "x",
					"data" : 12242095746
				},
				"timeout" : {
					"type" : "x",
					"data" : 25000000
				},
				"progress" : {
					"type" : "i",
					"data" : -1
				}
			},
			{
				"body" : {
					"type" : "s",
					"data" : ""
				},
				"message" : {
					"type" : "s",
					"data" : ""
				},
				"summary" : {
					"type" : "s",
					"data" : ""
				},
				"appname" : {
					"type" : "s",
					"data" : "Thunderbird"
				},
				"category" : {
					"type" : "s",
					"data" : ""
				},
				"default_action_name" : {
					"type" : "s",
					"data" : "default"
				},
				"icon_path" : {
					"type" : "s",
					"data" : ""
				},
				"id" : {
					"type" : "i",
					"data" : 4
				},
				"timestamp" : {
					"type" : "x",
					"data" : 4428028382
				},
				"timeout" : {
					"type" : "x",
					"data" : 10000000
				},
				"progress" : {
					"type" : "i",
					"data" : -1
				}
			},
			{
				"body" : {
					"type" : "s",
					"data" : "2-Minuten-Umfrage zur Bearbeitung Deiner Störungsmeldung von Vodafone"
				},
				"message" : {
					"type" : "s",
					"data" : "<b> hat 1 neue Nachricht</b>\n2-Minuten-Umfrage zur Bearbeitung Deiner Störungsmeldung von Vodafone"
				},
				"summary" : {
					"type" : "s",
					"data" : " hat 1 neue Nachricht"
				},
				"appname" : {
					"type" : "s",
					"data" : "Thunderbird"
				},
				"category" : {
					"type" : "s",
					"data" : ""
				},
				"default_action_name" : {
					"type" : "s",
					"data" : "default"
				},
				"icon_path" : {
					"type" : "s",
					"data" : ""
				},
				"id" : {
					"type" : "i",
					"data" : 3
				},
				"timestamp" : {
					"type" : "x",
					"data" : 3421412401
				},
				"timeout" : {
					"type" : "x",
					"data" : 10000000
				},
				"progress" : {
					"type" : "i",
					"data" : -1
				}
			},
			{
				"body" : {
					"type" : "s",
					"data" : ""
				},
				"message" : {
					"type" : "s",
					"data" : "<b> hat 1 neue Nachricht</b>\nIhre Bestellung bei EDEKA Rübsam (#1277) - Update von EDEKA Rübsam\n<p>Guten Tag, Andre Albani,</p><p>unsere"
				},
				"summary" : {
					"type" : "s",
					"data" : " hat 1 neue Nachricht"
				},
				"appname" : {
					"type" : "s",
					"data" : "Thunderbird"
				},
				"category" : {
					"type" : "s",
					"data" : ""
				},
				"default_action_name" : {
					"type" : "s",
					"data" : "default"
				},
				"icon_path" : {
					"type" : "s",
					"data" : ""
				},
				"id" : {
					"type" : "i",
					"data" : 2
				},
				"timestamp" : {
					"type" : "x",
					"data" : 30491854
				},
				"timeout" : {
					"type" : "x",
					"data" : 10000000
				},
				"progress" : {
					"type" : "i",
					"data" : -1
				}
			}
		]
	]
}

The two commands output this

Offline

#18 2023-05-16 14:25:21

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: dunst plugin for the taskbar

It looks like this is the problem:

[2] App: Thunderbird
<b> hat 1 neue Nachricht</b> - Ihre Bestellung bei EDEKA Rübsam (#1277) - Update von EDEKA Rübsam - <p>Guten Tag, Andre Albani,</p>unsere
</markup>' from markup due to error parsing markup: Unknown tag 'p' on line 16 char 107

It's not properly handling the embedded tags. So lets remove them. Try this version instead:

#!/bin/bash
# requires dunst, jq & zenity

# max number of items to display in tooltip
ITEMSTODISPLAY=5

# get dunst outputs
HISTORY=5
OUT=$(cat dunst.log)

# change the colour of the plugin depending on history
[[ $HISTORY -gt 0 ]] && COLOR=white || COLOR=white

# clamp number of items to display in tooltip
[[ $HISTORY -ge $ITEMSTODISPLAY ]] && NUMITEMS=$ITEMSTODISPLAY || NUMITEMS=$HISTORY

# retrieve notification data
for (( c=0; c<$NUMITEMS; c++ ))
do
	MESSAGE[$c]=$(echo $OUT | jq ".data[][$c].message.data" | sed 's/\"//g' | sed -e 's/<[^>]*>//g')
	APPNAME[$c]=$(echo $OUT | jq ".data[][$c].appname.data" | sed 's/\"//g')
	ID[$c]=$(echo $OUT | jq ".data[][$c].id.data")
done

# do the genmon
if [ $NUMITEMS == 0 ]; then
    echo "<txt><span foreground='$COLOR'>  </span></txt>"
else
    echo "<txt><span foreground='$COLOR'> <sup>$HISTORY</sup> </span></txt>"
fi
echo "<txtclick>sh -c 'zenity --question --title \"Delete dunst history\" --default-cancel && dunstctl history-clear'</txtclick>"
echo "<tool>Notification History:"
for (( c=0; c<$NUMITEMS; c++ ))
do
	echo ""
	echo "[${ID[$c]}] App: ${APPNAME[$c]}"
	echo "${MESSAGE[$c]}" | sed 's/\\n/ - /g'
done

echo "</tool>"

exit 0

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#19 2023-05-16 15:41:43

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

Der Code zeigt bloß das an:
bildschirmfoto.png

And where does the dunst.log come from?

Last edited by aalbani (2023-05-16 16:05:58)

Offline

#20 2023-05-16 16:17:07

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: dunst plugin for the taskbar

Oops, sorry. I was testing with your output. Try this instead:

#!/bin/bash
# requires dunst, jq & zenity

# max number of items to display in tooltip
ITEMSTODISPLAY=5

# get dunst outputs
HISTORY=$(dunstctl count history)
OUT=$(dunstctl history)

# change the colour of the plugin depending on history
[[ $HISTORY -gt 0 ]] && COLOR=white || COLOR=white

# clamp number of items to display in tooltip
[[ $HISTORY -ge $ITEMSTODISPLAY ]] && NUMITEMS=$ITEMSTODISPLAY || NUMITEMS=$HISTORY

# retrieve notification data
for (( c=0; c<$NUMITEMS; c++ ))
do
	MESSAGE[$c]=$(echo $OUT | jq ".data[][$c].message.data" | sed 's/\"//g' | sed -e 's/<[^>]*>//g')
	APPNAME[$c]=$(echo $OUT | jq ".data[][$c].appname.data" | sed 's/\"//g')
	ID[$c]=$(echo $OUT | jq ".data[][$c].id.data")
done

# do the genmon
if [ $NUMITEMS == 0 ]; then
    echo "<txt><span foreground='$COLOR'>  </span></txt>"
else
    echo "<txt><span foreground='$COLOR'> <sup>$HISTORY</sup> </span></txt>"
fi
echo "<txtclick>sh -c 'zenity --question --title \"Delete dunst history\" --default-cancel && dunstctl history-clear'</txtclick>"
echo "<tool>Notification History:"
for (( c=0; c<$NUMITEMS; c++ ))
do
	echo ""
	echo "[${ID[$c]}] App: ${APPNAME[$c]}"
	echo "${MESSAGE[$c]}" | sed 's/\\n/ - /g'
done

echo "</tool>"

exit 0

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#21 2023-05-17 04:26:24

aalbani
Member
Registered: 2023-03-30
Posts: 28

Re: dunst plugin for the taskbar

So far it works.
Thanks again.

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.008 seconds, 7 queries executed - Memory usage: 661 KiB (Peak: 693.84 KiB) ]