working calendar alarms

This commit is contained in:
Anish Lakhwara 2022-12-18 01:02:14 +10:00
parent 30d6281a8f
commit 00c9c074c1
2 changed files with 6 additions and 46 deletions

View file

@ -35,7 +35,7 @@
origin = top-right origin = top-right
# Offset from the origin # Offset from the origin
offset = 22x28 offset = 18x36
# Scale factor. It is auto-detected if value is 0. # Scale factor. It is auto-detected if value is 0.
scale = 0 scale = 0
@ -182,7 +182,7 @@
hide_duplicate_count = true hide_duplicate_count = true
# Display indicators for URLs (U) and actions (A). # Display indicators for URLs (U) and actions (A).
show_indicators = yes show_indicators = no
### Icons ### ### Icons ###

View file

@ -5,53 +5,13 @@
serviceConfig.Type = "simple"; serviceConfig.Type = "simple";
path = [ path = [
pkgs.libnotify pkgs.libnotify
pkgs.dunstify pkgs.dunst
pkgs.khal pkgs.khal
pkgs.unixtools.column
pkgs.diffutils
]; ];
startAt = "*08:00:00"; startAt = "*08:00:00";
script = '' script = builtins.readFile ./alarm.sh;
#!/usr/bin/env bash
cache_file="${XDG_CACHE_HOME:-$HOME/.cache}/khal-events"
# events starting in the next TIMESPAN will trigger an alarm
timespan='60min'
# this is needed for cronjobs and Xorg
export DISPLAY=":0"
snooze_string='💤 Snooze all.'
dismiss_string=' Dismiss all.'
# only show events with ⏰ symbol (=has alarm set)
# remove arrows for all-day events to only have one notification
# remove ⏰ symbol because it is obvious
events="$(khal list --format \
'{cancelled}{start-style}{to-style}{end-style} {title}{description-separator}{description}{location}{repeat-symbol}{alarm-symbol}' \
now "${timespan}" \
| sed -ne '// p' \
| sed -e 's///g' -e 's/\(\|\|\)[^[:blank:]]*/all-day/g' \
| column -tl 3)"
# get events that are new compared to cache file
new_events="$(diff -NwU 0 "${cache_file}" - << EOF | sed -ne '/^\+[^+]/ p' \
| sed -ne 's/^\+\([[:print:]].*\)$/\1/p'
${events}
EOF
)"
[ -z "${new_events}" ] && exit 0
action="$(dunstify --action="default,Dismiss" --action="snooze,Snooze" "${new_events}")"
case "${action}" in
"snooze")
;;
"default")
printf '%s' "${events}" > "${cache_file}"
;;
*)
printf '%s' "${events}" | grep -Fve "${input}" > "${cache_file}"
;;
esac
'';
serviceConfig = { serviceConfig = {
User = "anish"; User = "anish";
Environment = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus"; Environment = "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus";