Re: Notifying about errors from user menu items?
Guy Stalnaker via mc <[email protected]> Sat, 24 Aug 2024 17:24:34 -0500
| Newsgroups | gmane.comp.gnome.apps.mc.general |
|---|---|
| Message-ID | <CAGHXqCbYhXJbU-OfdmBm8U2=iPRG2aYpj4XfVSDXfxO7JaWtgw@mail.gmail.com> |
GAH! GMail sent that before I wanted it to. Note that in my UserMenu code, the set commands are indented (else they'd not be put into the temp script file by MC). -- “Happiness is the meaning and the purpose of life, the whole aim and end of human existence.” ― Aristotle On Sat, Aug 24, 2024 at 5:23 PM Guy Stalnaker <[email protected]> wrote: > TL;DR > > Hello - I was intrigued by your post to the list, so I did some > experimenting about ways to get output from a command into a notification > dialog such as you show. > > With a bit of CLI fiddling and work in MC I found a way to use redirection > to a file, the contents of which can then be used by notify-send. This way > you can use the same notify-send syntax for any use of it. Thus ... > > $ <command plus syntax> 2>&1 /tmp/tmp_out && notify-send --urgency=normal > -t 10000 -i dialogerror -a "ERROR" "$(cat /tmp/tmp_out)" > > My test usage from a terminal was: > > $ cat ./tmp 2>&1 | tee /tmp/tmp_out && notify-send -i dialogerror -a > "ERROR" "$(cat /tmp/tmp_out)" > > Where a file named 'tmp' does not exist. The cat command will respond with > a "does no exist" error. That command above creates the tmp file and a > notification popup is displayed with the expected "does not exist" error > output. > > This puts both STDOUT and STDERR into that /tmp/tmp_out file. If you only > want stderr, modify the "2>&1" part after the command to "2>" (that is > remove the "&1" part). > > One can also add a subsequent command to remove that temp file, but it > should be overwritten by every command call since the syntax is "2>&1" or > "2>" (if one uses two >>, then the output is appended, which is not what > one would want in this usage). > > Here's what my test UserMenu item has in it for only STDERR: > > [code] > 0 Convert mp3 file(s) to wav > set -x > CMD='/usr/bin/lame --decode' > for i in %s ; do > $CMD "$i" 2> /tmp/tmp_out && notify-send -i dialogerror -a "ERROR" > "$(cat /tmp/tmp_out)" > done > set +x > [/code] > > And I get some output one can see with CTRL-o after the Notify dialog > exits. > > > $ /bin/sh /tmp/mc-guyst/mcusrGDE6S2 > + CMD=/usr/bin/lame --decode > + /usr/bin/lame --decode 06-the-mysterious-mr.-quin-agatha-christie.png > + cat /tmp/tmp_out > input: 06-the-mysterious-mr.-quin-agatha-christie.png > (44.1 kHz, 2 channels, raw PCM data) > output: 06-the-mysterious-mr.-quin-agatha-christie.png.wav > (16 bit, Microsoft WAVE) > Frame# 29/29 0 kbps > + set +x > > To get an error, I put the cursor in MC on an image file, which lame > cannot convert. The /tmp/tmp_out file is successfully created and > notify-send does put up a notification dialog as desired. In MC %s and %S > are macro substitutions for the selected files: The tagged files if there > are any. Otherwise the current file. It's interesting that set -x doesn't > seem to "see" what follows the && in the command line as it's not shown in > the output (the cat command is, but not the notify-send and its params). > > When it's working as desired one can remove the set syntax, or keep it as > a way of always seeing the output. One can also put in code to explicitly > remove the /tmp/tmp_out file, but I'd rather keep it so it can be checked > in anohther terminal or with Ctrl-o since it will always be overwritten the > next time this is used. > > I don't know if there is a Midnight-Commander way to pass command error > output into MC, but this is right useful in my opinion. > > Thanks for your list email that got me thinking of it. > > -- > > “Happiness is the meaning and the purpose of life, the whole aim and end > of human existence.” > > ― Aristotle > > > > On Tue, Aug 20, 2024 at 12:36 AM skejg via mc < > [email protected]> wrote: > >> >> Hi! >> >> >> How do you guys handle errors when launching user menu items, for >> example? >> >> Like, if you select a menu item, run it, it fails, prints something to >> /dev/sderr, then what do you do not to miss it? Always perform <C-o> to >> check the output? Notify yourself somehow? Something else? >> >> For now, I just try to construct menu items like this: >> >> git am -3 %d/%f \ >> || notify-send -i dialog-error -a "ERROR" "The patch was aborted" >> >> But maybe there's a better way? More *MC-like* way? :) >> >> >> Thanks! >> >> >> -- >> skejg >> >> -- >> mc mailing list >> [email protected] >> https://lists.midnight-commander.org/mailman/listinfo/mc >> > -- mc mailing list [email protected] https://lists.midnight-commander.org/mailman/listinfo/mc