Setting up a desktop notification in Ubuntu after login

The following actions have been tested successfully on Ubuntu 19.04

Setting a desktop notification in Ubuntu after login requires creating a Desktop application following the Freedesktop specifications.
All such applications run as a user must be located in $HOME/.config/autostart

The autostart folder may not exist.
If not :

mkdir -p $HOME/.config/autostart

As an example, this desktop application will be named welcome.desktop

Create this file as follows :


touch $HOME/.config/autostart/welcome.desktop

Add the following lines in it :

cat welcome.desktop

[Desktop Entry]
Type=Application
Exec=/home/$USERNAME/Tools/
welcome_msg.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=myscript
Comment=Startup Script

Create the bash script welcome_msg.sh that will display the notification message :

cat welcome_msg.sh

#!/usr/bin/env bash

notify-send “Good morning ${USERNAME^} !” “Did you check your backups ?”

Make sure that the Exec field in your welcome.desktop file points to your script.

Reboot your Ubuntu machine and log in. Your custom desktop notification will be displayed !

Further readings :

https://cloudkul.com/blog/display-notification-login-ubuntu/

XDG autostart specification

Different ways of autostarting applications in Linux

Desktop Application Autostart Specification

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.