Raum Remind Widget

From awesome
Jump to: navigation, search

This widget shows the next reminder in my wibox. I use this so I don't forget any appointments. You can read more about it [Here]

It consists of two parts, a shellscript that outputs the next reminder and the lua widget that outputs it to the wibox.

The shellscript (reminderwidget.sh):

 #!/bin/bash
 #Configurables:
 MONTHSTOCHECKAHEAD=12
 REMINDERSFILE=/home/USERNAME/.reminders
  
 #Helper function to check if a date is in the future
 is_futuredate()
 {
     TODAY=$(date +%s)
     COMPARE=$(date -d "$(date -d "$1")" +%s)
     test $(($COMPARE-TODAY)) -le 0 && return 1 || return 0
 }
  
 #This gives a nice and structured output of coming reminders
 remind -s$MONTHSTOCHECKAHEAD -b1 $REMINDERSFILE |
 while read line
 do
     #Check if the reminder has a duration, I'm only interested in those
     if [ "$(echo "$line" | cut -d' ' -f 4)" != "*" ]; then
         #Extract the date, time and duration
         DATE=$(echo "$line" | cut -d' ' -f 1)
         TIMES=$(echo "$line" | cut -d' ' -f 6)
         STARTTIME=$(echo "$TIMES" | cut -d'-' -f 1)
         BEGDATETIME=$(date -d "$(echo $DATE $STARTTIME)")
         DURMINS=$(echo "$line" | cut -d' ' -f 4)
         #Calculate the end of the reminder
         ENDDATETIME=$(date -d "$(echo $BEGDATETIME +$DURMINS minutes)")
  
         #Check if the ending of this reminder is still in the future
         if is_futuredate "$ENDDATETIME"; then
             #Check if the beginning is in the past
             if ! is_futuredate "$BEGDATETIME"; then
                 echo "NOW: $(echo "$line" | cut -d' ' -f 6-)"
                 exit
             fi
             echo "$(echo "$line" | cut -d' ' -f 1,6-)"
             exit
         fi
     fi
 done

All this script does is output the next reminder. It's output is passed to a widget with the following lua code:

 -- {{{ Next reminder
 -- remindericon = widget({ type = "imagebox" })
 -- remindericon.image = image(beautiful.widget_org)
 myreminder = widget({ type = "textbox", name = "reminder", align = "right" })
 function next_reminder()
     local fd=io.popen("bash /home/USER/Scripts/reminderwidget.sh", "r") --next reminder
     local line=fd:read()
     return line
 end
 myreminder.text = " " .. next_reminder() .. " "
 my_reminder_timer=timer({timeout=115}) 
 my_reminder_timer:add_signal("timeout", function()
     myreminder.text = " " .. next_reminder() .. " "
 end)
 my_reminder_timer:start()
 -- }}}


Don't forget to add it:

      statusbar[s].widgets = ({
         ....
         myreminder,
         ...
     })
Personal tools