2

When I discovered alias last I night encountered one called alert which calls notify-send which should pop up a GUI bubble messages on the Desktop. In my case it's mulit-monitor with the TV defined over the built-in laptop in the virtual screen. As such notification bubbles (for example volume control) show up on the TV.

Last night when I tested:

alert "Weather Update: It's raining Red States"

nothing appeared. At first another AU user and myself thought it was because Youtube was running full screen and the Google Chrome Window was defined as "always on top". It turns out that wasn't the real problem and it's an on-again off-again problem.

How can I get alert alias to always work?

PS: I searched similar questions but they either went unanswered and/or do not reference the alert alias which I want to use because the native command is hard to remember, especially with necessary control paramters.

WinEunuuchs2Unix
  • 99,709
  • 34
  • 237
  • 401
  • I don't see why you created a new post for this. This should been the answer to http://askubuntu.com/questions/847302/something-has-set-up-an-alias-i-dont-understand-alert – muru Nov 11 '16 at 07:41
  • @muru There were a few reasons: 1. that question is vote closed as a duplicate which tells me "don't look here, move on". 2. that question has an accepted answer and I didn't want to diminish that author's work. 3. this "answer your own question" format seems "cleaner" without exploratory back and forth comments. – WinEunuuchs2Unix Nov 11 '16 at 11:08
  • 1. It's not closed *yet*. 2. If the problem hasn't been solved fully, you should have told the answerer so. Accepting isn't permanent. Un-accepting doesn't diminish their effort, but it does diminish the utility to future visitors, since now they think an incomplete answer is the solution. – muru Nov 11 '16 at 11:09
  • Seth was able to merge two threads into one and delete the close voted duplicate a few days ago. Do you think something along that line is appropriate in this case? – WinEunuuchs2Unix Nov 11 '16 at 11:21
  • No, since you're the poster of both Q's, but you can ask – muru Nov 11 '16 at 11:23
  • Should I vote close the proposed duplicate? I view it very low quality and confusing as I was totally clueless when I wrote it a few days ago. – WinEunuuchs2Unix Nov 11 '16 at 11:26

2 Answers2

3

Aliases are automatically created in ~/.bashrc

When you look in ~/.bashrc you see these lines:

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

The problem with the code is the --urgency=low flag. Sometimes the message pops up, some times it doesn't. After all it is low priority right?

To make the message always appear set the urgency to critical. Rather than changing the system default I created a new line for my own purposes:

# Add a "redalert" alias to pop-up on GUI desktop screens.  Use like so:
#   redalert "Weather update: It's raining Red States"
alias redalert='notify-send --urgency=critical -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

Now you can use:

redalert "Weather Update: It's raining Red States"

and it works perfectly!

WinEunuuchs2Unix
  • 99,709
  • 34
  • 237
  • 401
1

alert is not intended to be used the same way as notify-send. If you want a catchier name for notify-send, create a function, since aliases are deprecated. For example:

popup(){
    notify-send "$@"
}
wjandrea
  • 14,109
  • 4
  • 48
  • 98
  • I just learned about them and then I find out `Aliases` are deprecated :(. One cool alias I discovered reading ~/.bashrc yesterday was `l` (lower case L). Where should these new functions be defined? – WinEunuuchs2Unix Nov 11 '16 at 11:13
  • @WinEunuuchs2Unix Define them at the bottom of `~/.bashrc` – wjandrea Nov 11 '16 at 14:52
  • That was my first thought but I wasn't confident it was the right place. Thanks for confirmation! I'm planning on enhancing "popup" with icons such as an alarm clock. Also will include optional parameters to play system event sound files. Conversion to "popup" therefore will be a gradual transition away from deprecated aliases. I'll post the final function in a new Q&A some day. +1 for Future Proofing suggestion. – WinEunuuchs2Unix Nov 11 '16 at 15:12