¿Cómo puedo enviar una notificación de escritorio personalizada?


97

Tengo un script personalizado y quiero enviar una notificación de escritorio (la que aparece en la esquina superior derecha de la pantalla) con un mensaje personalizado. ¿Cómo puedo hacer eso?

Respuestas:


149

Hay muchas otras características interesantes con notify-send

Podemos ejecutar un comando y hacer que se muestre en la notificación:

notify-send <title> <`command`>
notify-send Date "`date`"
notify-send Disk "`df / -H`"

Podemos usar íconos con las notificaciones

notify-send -i <icon> <Message>
notify-send -i face-wink "Hello! January"

Pop up realmente molesto

notify-send  -t 0 "Bringing down the system"

y

notify-send <title> <message>
notify-send "who am i" "I am January"

Para más opciones ver aquí


1
Gracias. ¿Dónde podemos obtener una lista de iconos, por ejemplo, el face-winkque utilizó?
Paddy Landau

3
mira

notify-send -t 0funciona pero notify-send "who am i" "I am January"no funciona :( - en ubuntu 15.10
AlikElzin-kilaka

3
Trabajado con--urgency=critical
AlikElzin-Kilaka

Instalación en debian sudo apt install libnotify-bin.
user149244

18

Solo para agregar a las otras respuestas, cuando ejecuto el comando localmente desde cron, uso

DISPLAY=:0.0 /usr/bin/notify-send "TITLE" "MESSAGE"

12

Me topé con ese por casualidad. Respuesta: usa el programa notify-send:

notify-send "Hello world!"

2

Creé un script simple y casi nativo que reproduce sonido y muestra una notificación con un mensaje y hora dados para Ubuntu ( Gist ):

#!/bin/sh

# https://gist.github.com/John-Almardeny/04fb95eeb969aa46f031457c7815b07d
# Create a Notification With Sound with a Given Message and Time
# The Downloaded Sound is from Notification Sounds https://notificationsounds.com/

MSSG="$1"
TIME="$2"

# install wget if not found
if ! [ -x "$(command -v wget)" ]; then 
    echo -e "INSTALLING WGET...\n\n"
    sudo apt-get install wget
    echo -e "\n\n"
fi

# install at package if not found
if ! [ -x "$(command -v at)" ]; then
    echo -e "INSTALLING AT...\n\n"
    sudo apt-get install at
    echo -e "\n\n"
fi

# install sox if not found
if ! [ -x "$(command -v sox)" ]; then
    echo -e "INSTALLING SOX...\n\n"
    sudo apt-get install sox
    sudo apt-get install sox libsox-fmt-all
    echo -e "\n\n"
fi

# download the noti sound if this is first time
# add alias to the bashrc file
if ! [ -f ~/noti/sound.mp3 ]; then
    echo -e "DOWNLOADING SOUND...\n\n"
    touch ~/noti/sound.mp3 | wget -O ~/noti/sound.mp3 "https://notificationsounds.com/wake-up-tones/rise-and-shine-342/download/mp3"
    sudo echo "alias noti=\"sh ~/noti/noti.sh\"" >> ~/.bashrc
    source ~/.bashrc        
    echo -e "\n\n"
fi

# notify with the sound playing and particular given message and time
echo "notify-send \""$MSSG\"" && play ~/noti/sound.mp3" | at $TIME

¿Cómo utilizar?

Primera ejecución - Configuración:

  1. Cree un nuevo directorio en su hogar y llámelo noti

    mkdir ~/noti
    
  2. Descargue noti.sh y extráigalo al notidirectorio anterior .

  3. Abra la Terminal y cambie el directorio a noti

    cd ~/noti
    
  4. Haga que noti.sh sea ejecutable emitiendo:

    sudo chmod +x noti.sh
    
  5. Ejecute una prueba como esta:

    sh ~/noti/noti.sh "Test" "now"
    

Ejemplos

noti "Hello From Noti" "now +1 minute"
noti "Hello From Noti" "now +5 minutes"
noti "Hello From Noti" "now + 1 hour"
noti "Hello From Noti" "now + 2 days"
noti "Hello From Noti" "4 PM + 2 days"
noti "Hello From Noti" "now + 3 weeks"
noti "Hello From Noti" "now + 4 months"
noti "Hello From Noti" "4:00 PM"
noti "Hello From Noti" "2:30 AM tomorrow"
noti "Hello From Noti" "2:30 PM Fri"
noti "Hello From Noti" "2:30 PM 25.07.18"

Para notificar el final del proceso (ejemplo)

sudo apt-get update; noti "Done" "now"
Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.