Skip to content

Instantly share code, notes, and snippets.

@kun-zhou
Last active May 21, 2023 11:29
Show Gist options
  • Save kun-zhou/2800969ec8bdde7e42d5613616ba7898 to your computer and use it in GitHub Desktop.
Save kun-zhou/2800969ec8bdde7e42d5613616ba7898 to your computer and use it in GitHub Desktop.
This script is used to fetch calendar entries from `khal` and set up reminders through `notify-send` 10 minutes ahead using `at` utility. It is supposed to be executed whenever your calendar update. If you use `vdirsyncer`, probably you would want run this script after running `vdirsyncer sync`
#!/usr/bin/bash
# The line below extracts the events in each line and add quotes to them so for loop will loop through each of them
items=`khal list today|tail -n +2 #no longer needed|awk -F"\n" '{printf("\"%s\"\n"),$1}'`
echo "$items"|while read -r rem # I pipe the list because otherwise the loop will treat blank space as delimiter
do
rm_time=$(($(date +%s --date "`echo $rem | sed -n 's/^\([0-9][0-9]:[0-9][0-9]\)-.*/\1:00/p'`") - 600)) # this command extracts the starting time of the event, and convert it to EPOCH, and subtract 10 minutes from it.
rm_time=`date +%H:%M --date @$rm_time` # This converts EPOCH back to human readble form
rem_name=`echo $rem | sed -n 's/.*:[0-9][0-9] \(.*\)/\1/p'`
echo "notify-send 'Calendar Reminder: $rem_name'" | at $rm_time today
done
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment