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.

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!

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,504