Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Create a Notification With Sound with a Given Message and Time in Linux-Like OS
# Create a Notification With Sound with a Given Message and Time
# The Downloaded Sound is from Notification Sounds
# 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"
# 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"
# 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"
# 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 ""
sudo echo "alias noti=\"sh ~/noti/\"" >> ~/.bashrc
source ~/.bashrc
echo -e "\n\n"
# notify with the sound playing and particular given message and time
echo "notify-send \""$MSSG\"" && play ~/noti/sound.mp3" | at $TIME
Copy link

John-Almardeny commented Jul 10, 2018

How To Use?

First Run - Setting Up:

  1. Create a new Directory at your home and call it noti
    mkdir ~/noti
  2. Download and extract it to the above noti dir.
  3. Open Terminal and Change Directory to noti
    cd ~/noti
  4. Make executable by issuing:
    sudo chmod +x
  5. Run a Test like this:
    sh ~/noti/ "Test" "now"

Creating Notification Examples

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"

For Notifying The Finish of Process (example)

sudo apt-get update; noti "Done" "now"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment