You are not logged in.

#1 2023-02-28 11:02:01

duyinthee
Member
Registered: 2015-06-14
Posts: 222
Website

[SOLVED] multiple line of output in notify-send?

Hello, everyone, thanks in advance.

$ aa=$(brightnessctl)
$ notify-send "brightness" "$aa"

shows as I expect, multiple lines in one notification. But

$ brightnessctl | while read aa; do notify-send "brightness" "$aa"; done

shows multiple notifications instead of multiple lines in one notification, because brightnessctl command's output is multiple lines.

How can I solve this so that to show one notification and multiple lines in it?

Last edited by duyinthee (2023-03-02 08:14:40)

Offline

#2 2023-02-28 11:23:36

mpan
Member
Registered: 2012-08-01
Posts: 1,188
Website

Re: [SOLVED] multiple line of output in notify-send?

notify-send accepts multiline input just fine.

The problem is not with notify-send, but with the script. It does not pass multiple lines as the argument. It splits lines and invokes notify-send for each one separately.

The solution is… to not split them. You already provided the valid code yourself.

Last edited by mpan (2023-02-28 11:25:31)


Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#3 2023-03-02 02:32:27

duyinthee
Member
Registered: 2015-06-14
Posts: 222
Website

Re: [SOLVED] multiple line of output in notify-send?

Thanks for reply.
I now have this solution

#!/bin/dash

ptnt () {
    msg=$(while read opt; do echo "$opt"; done)
    notify-send -t 7000 "brightness" "$msg"
}

brightnessctl 2>&1 | ptnt

but I still have an issue to solve. What if I want to pip only stderr to notify-send (not stdout)?
How to pip only command not found error to notify-send in the following;

#!/bin/dash

ptnt () {
    msg=$(while read opt; do echo "$opt"; done)
    notify-send -t 7000 "brightness" "$msg"
}

brightnessctl 2>&1 | ptnt
bbbbbrightnessctl 2>&1 | ptnt

I tested changing this part 2>&1 in many forms, but not work.

Last edited by duyinthee (2023-03-02 02:37:02)

Offline

#4 2023-03-02 03:05:30

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 237

Re: [SOLVED] multiple line of output in notify-send?

Do you want to display each LED info in separate notification? You can split brightnessctl output by empty lines, e.g.:

$ brightnessctl | awk -v RS='' '{printf $0"\0"}' | xargs -r0 -n1 notify-send

Offline

#5 2023-03-02 04:26:40

mpan
Member
Registered: 2012-08-01
Posts: 1,188
Website

Re: [SOLVED] multiple line of output in notify-send?

Since you are using dash, I can’t really help.

However, if redirection works the same as in bash, you did not redirect stdout to anywhere, so it is mixed with stderr. You need to redirect stdout to somewhere else. For example to “/dev/null” if it is not needed:

command 2>&1 >/dev/null

Sometimes I seem a bit harsh — don’t get offended too easily!

Offline

#6 2023-03-02 06:55:20

seth
Member
Registered: 2012-09-03
Posts: 49,950

Re: [SOLVED] multiple line of output in notify-send?

dimich wrote:

Do you want to display each LED info in separate notification?

OP wrote:

How can I solve this so that to show one notification and multiple lines in it?

msg=$(while read opt; do echo "$opt"; done)

wtf…

notify-send -t 7000 "brightness" "$(brightnessctl 2>&1 1>/dev/null)"

Online

#7 2023-03-02 08:14:20

duyinthee
Member
Registered: 2015-06-14
Posts: 222
Website

Re: [SOLVED] multiple line of output in notify-send?

Thanks all for helpful replies. Yes,

2>&1 1>/dev/null

works perfect.

Offline

Board footer

Powered by FluxBB