summaryrefslogtreecommitdiff
path: root/src/Mutt:Email_Notifications.adoc
blob: 980f5560e6d466dbeb70eafaec1f68b52b25b101 (plain)
    1 Mutt:Email Notifications
    2 ========================
    3 :author: Aaron Ball
    4 :email: nullspoon@iohq.net
    5 
    6 
    7 == {doctitle}
    8 
    9 I use the http://www.mutt.org/[mutt] email client for all of my email accounts
   10 (in combination with mbsync for offline mail). One of the things I've hear
   11 quite a few people complain about is its lack of notification integration, be
   12 it through libnotify, system sounds, or any other means. Rightefully so, it is
   13 a bit annoying to have to keep checking your terminal for new mail. With that,
   14 I wrote a simple script to remedy the issue.
   15 
   16 This script uses the inotify-tools to watch the given directory for new files
   17 without having to loop and execute commands every x seconds, consuming many
   18 system resources. Inotify is very small and will not bog down your machine (it
   19 uses the linux kernel inotify subsystem to sleep until triggered by the
   20 specified filesystem event).
   21 
   22 ----
   23 #!/usr/bin/env bash
   24 
   25 # Command to be executed when a change occurs
   26 cmd='mplayer -really-quiet ~/.sounds/notify.ogg'
   27 
   28 # Require user to specify directory to be watched
   29 if [[ -z ${1} ]]; then
   30   echo "Please specify a directory to be monitored."
   31   exit 1
   32 fi
   33 
   34 monpath=${1}
   35 
   36 # Verify directory to be monitored exists
   37 if [[ ! -d ${monpath} ]]; then
   38   echo "Path ${monpath} does not exist. Please check the path and try again."
   39   exit 1
   40 fi
   41 
   42 echo "Monitoring ${monpath}"
   43 
   44 while [ 0==0 ]; do
   45   # Wait for a file creation operation
   46   inotifywait -e create -r "${monpath}"
   47   # Display with really quiet because mplayer is chatty
   48   ${cmd}
   49 done
   50 ----
   51 
   52 
   53 [[usage]]
   54 == Usage
   55 
   56 To use this script, save its source to a path where it can be called easily. I
   57 put mine at __~/bin/dir_notify.sh__.
   58 
   59 Once you've tweaked the cmd variable to your liking, simply execute the script
   60 and background by following the command with a & if you like.  Send yourself a
   61 few emails to test it.
   62 
   63 ----
   64 dir_notify.sh ~/Mail
   65 ----
   66 
   67 Category:Mutt
   68 Category:Linux
   69 Category:Scripts
   70 
   71 // vim: set syntax=asciidoc:

Generated by cgit