User Tools

Site Tools


linux:notifications

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
linux:notifications [2020/07/17 20:26] Wulf Rajeklinux:notifications [2023/05/29 11:55] (current) – external edit 127.0.0.1
Line 21: Line 21:
 <code> <code>
 ./notify-send.sh --expire-time=-1 --icon=/usr/share/icons/Humanity/apps/24/application-x-vnc.svg Subject Message ./notify-send.sh --expire-time=-1 --icon=/usr/share/icons/Humanity/apps/24/application-x-vnc.svg Subject Message
 +</code>
 +
 +Alternative bash script inspired by notify-send:
 +<code>
 +#!/bin/bash
 +NOTIFY_ARGS=(--session
 +             --dest org.freedesktop.Notifications
 +             --object-path /org/freedesktop/Notifications)
 +APP_NAME="${0##*/}"
 +REPLACE_ID=0
 +EXPIRE_TIME=4000
 +ICON="/usr/share/icons/Humanity/apps/48/application-x-vnc.svg"
 +parse_notification_id(){
 +    sed 's/(uint32 \([0-9]\+\),)/\1/g'
 +}
 +
 +HOSTNAME_TO_IGNORE_REGEX="\.example\.com"
 +#VNC loop
 +while true
 +do
 +  LOGGEDON=$(netstat -a -n | grep ":5900" | grep ESTABLISHED | sed 's/.*:5900 *\(.*\):.*/\1/g' | while read i; do host -t CNAME $i | head -1; done | sed 's/.* \(.*\)$HOSTNAME_TO_IGNORE_REGEX\./\1/g')
 +  if [ "`echo $LOGGEDON|wc -l`" -lt "2" ]
 +  then
 +    #Single VNC user, check again in 5 seconds
 +    sleep 5
 +  else
 +    #zenity --notification --text "Multiple VNC Conenctions:\n$LOGGEDON"
 +    HINTS="\"urgency\": <byte 1>"
 +
 +    NOTIFICATION_ID=$(gdbus call "${NOTIFY_ARGS[@]}"  \
 +                            --method org.freedesktop.Notifications.Notify \
 +                            "$APP_NAME" "$REPLACE_ID" "$ICON" "Multiple VNC Connections" \
 +                            "$LOGGEDON" \
 +                            "[$ACTION]" "{$HINTS}" "int32 $EXPIRE_TIME" \
 +                          | parse_notification_id)
 +    sleep 4
 +    gdbus call "${NOTIFY_ARGS[@]}"  --method org.freedesktop.Notifications.CloseNotification "$NOTIFICATION_ID" >/dev/null
 +    NOTIFICATION_ID=$(gdbus call "${NOTIFY_ARGS[@]}"  \
 +                            --method org.freedesktop.Notifications.Notify \
 +                            "$APP_NAME" "$REPLACE_ID" "$ICON" "Multiple VNC Connections" \
 +                            "$LOGGEDON" \
 +                            "[$ACTION]" "{$HINTS}" "int32 $EXPIRE_TIME" \
 +                          | parse_notification_id)
 +    sleep 4
 +    gdbus call "${NOTIFY_ARGS[@]}"  --method org.freedesktop.Notifications.CloseNotification "$NOTIFICATION_ID" >/dev/null
 +
 +  fi
 +  sleep 4
 +done
 </code> </code>
linux/notifications.1595014002.txt.gz · Last modified: 2023/05/29 11:53 (external edit)