✨ Found calcurse notification scripits, yet to use
This commit is contained in:
parent
5657acd06d
commit
58897644df
4 changed files with 166 additions and 0 deletions
|
|
@ -0,0 +1,13 @@
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
Version 2, December 2004
|
||||||
|
|
||||||
|
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
|
||||||
|
|
||||||
|
Everyone is permitted to copy and distribute verbatim or modified
|
||||||
|
copies of this license document, and changing it is allowed as long
|
||||||
|
as the name is changed.
|
||||||
|
|
||||||
|
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. You just DO WHAT THE FUCK YOU WANT TO.
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Calcurse Notifier
|
||||||
|
|
||||||
|
Simple bash script that sends notifications X minutes before events saved in calcurse. Will also send notifications X minutes before midnight for daily events. In addition, it has an explicit line for initiating vibration/sound with feedbackd on devices that support that.
|
||||||
|
|
||||||
|
Simply add something like the following to your crontab to enable. This line will notify you about events 30 minutes before they happen by running this script every two minutes.
|
||||||
|
```
|
||||||
|
*/2 * * * * export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus; /path/to/calendar_appointment_notify.sh 30 2
|
||||||
|
```
|
||||||
|
|
||||||
|
Dependencies:
|
||||||
|
|
||||||
|
`libnotify`
|
||||||
|
|
||||||
|
`calcurse`
|
||||||
|
|
||||||
|
`bc` (shell calculator) and `date`, which should be present on almost every UNIX-like system
|
||||||
|
|
||||||
|
optionally `feedbackd`
|
||||||
|
|
@ -0,0 +1,50 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# https://gitlab.com/tzcrawford/calcurse-notifier/
|
||||||
|
|
||||||
|
#Will send a notification if the next appointment in the next 24 hours occurs within $1 minutes
|
||||||
|
#Set $1 to be the time (minutes) you want the notification to pop up in advance before the appointment actually happens.
|
||||||
|
#This script should be executed by cron every minute or something like that thus it cannot run exactly $1 minutes before event.
|
||||||
|
#So we use $2 to be the time +/- of $1 that it is okay to send the notification.
|
||||||
|
#Probably set $2 this to the same period between when cron runs this script
|
||||||
|
|
||||||
|
notify_within=$1
|
||||||
|
script_frequency=$2
|
||||||
|
|
||||||
|
#if there are no appointments in the next two days, the stop right away
|
||||||
|
if [ "$(calcurse -a -d 2)" = "" ] ; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! [ "$(calcurse -n)" = "" ] ; then #There is an event today with an associated time
|
||||||
|
hours_remaining=$(calcurse -n | tail -1 | sed 's/ //g' | sed 's/\[//g' | sed 's/\].*//g' | sed 's/:..//g')
|
||||||
|
minutes_remaining=$(calcurse -n | tail -1 | sed 's/ //g' | sed 's/\[//g' | sed 's/\].*//g' | sed 's/..://g')
|
||||||
|
|
||||||
|
|
||||||
|
time_remaining=$( echo "$hours_remaining * 60 + $minutes_remaining" | bc ) #in minutes. just adding the hours to minutes
|
||||||
|
|
||||||
|
#Test whether the next event is within the given time frame
|
||||||
|
#We need bc (calculator) to do the calculation. Will return "1" if the conditional is true
|
||||||
|
#0.95 factor because you can get notifications to pop 3 times if cron is running every 1 minute and you use script_frequency=1
|
||||||
|
notify_boolean=$( echo "$time_remaining <= ($script_frequency*0.95 + $notify_within) && $time_remaining >= ($notify_within - $script_frequency*0.95)" | bc )
|
||||||
|
if [ "$notify_boolean" = 1 ] ; then
|
||||||
|
eventname="$(calcurse -n | sed -n 2p | sed 's/^ \[..:..\] //g')"
|
||||||
|
event_in="$(calcurse -n | sed -n 2p | sed 's/^ \[//g' | sed 's/\].*//g')"
|
||||||
|
notify-send "Appointment: ${eventname} in ${event_in}"
|
||||||
|
# fbcli -t -1 -E message-new-instant 2>&1 >/dev/null || true #send a request to vibrate and make sound with feedbackd if possible
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
tomorrow="$(date --date 'next day' +"%Y-%m-%d")"
|
||||||
|
daily_events="$(calcurse -a -d 2 | tr "\n" "@" | sed "0,/^.*${tomorrow}/ s///" | sed 's/^:@ \* //g' | sed 's/@ \* /, /g' | sed 's/@$//g' )" #Gives list of daily events tomorrow, Hopefully your event doesn't have "@" in it
|
||||||
|
if ! [ "$daily_events" = "" ] ; then
|
||||||
|
current_hour="$(date +"%H")"
|
||||||
|
current_minute="$(date +"%H")"
|
||||||
|
minutes_today=$(( $current_hour * 60 + $current_minute )) #Minutes that have elapsed today
|
||||||
|
minutes_left_today=$(( 24*60 - $minutes_today )) #Minutes elapsed at midnight
|
||||||
|
notify_boolean_2="$(echo "$minutes_left_today <= ($script_frequency*0.95 + $notify_within)" | bc )" #It is $notify_within minutes of midnight!
|
||||||
|
if [ "$notify_boolean_2" = 1 ] ; then
|
||||||
|
notify-send "Daily Events: $daily_events"
|
||||||
|
# fbcli -t -1 -E message-new-instant 2>&1 >/dev/null || true #send a request to vibrate and make sound with feedbackd if possible
|
||||||
|
fi
|
||||||
|
fi
|
||||||
85
scripts/calcurse_notification_attempts/calcurse_reminder.py
Executable file
85
scripts/calcurse_notification_attempts/calcurse_reminder.py
Executable file
|
|
@ -0,0 +1,85 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# https://askubuntu.com/questions/713822/how-can-i-use-the-notify-send-command-in-combination-with-the-calcurse-calendar
|
||||||
|
|
||||||
|
# python script that uses notify-send to tell you about what you have scheduled in calcurse
|
||||||
|
# parses the output and then uses system time to notify you
|
||||||
|
|
||||||
|
# calcurse -a
|
||||||
|
# 09/05/22:
|
||||||
|
# - 03:40 -> 03:40
|
||||||
|
# do stuff!!
|
||||||
|
# - 03:45 -> 03:45
|
||||||
|
# do some more stuff!!
|
||||||
|
|
||||||
|
# invoked like so... kinda janky, can be used a bash script as well I believe...
|
||||||
|
# calcurse_reminder 30
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
|
warn = int(sys.argv[1])
|
||||||
|
|
||||||
|
def get(command):
|
||||||
|
return subprocess.check_output(command).decode("utf-8")
|
||||||
|
|
||||||
|
def convert(t):
|
||||||
|
# convert set time into a calculate- able time
|
||||||
|
return [int(n) for n in t.split(":")]
|
||||||
|
|
||||||
|
def calc_diff(t_curr, t_event):
|
||||||
|
# calculate time span
|
||||||
|
diff_hr = (t_event[0] - t_curr[0])*60
|
||||||
|
diff_m = t_event[1] - t_curr[1]
|
||||||
|
return diff_hr + diff_m
|
||||||
|
|
||||||
|
def cleanup(done, newlist):
|
||||||
|
# clean up "done" -lists
|
||||||
|
for item in done:
|
||||||
|
if not item in newlist:
|
||||||
|
done.remove(item)
|
||||||
|
return done
|
||||||
|
|
||||||
|
def show_time(event, s = ""):
|
||||||
|
# show scheduled event
|
||||||
|
hrs = str(event[0][0]); mnts = str(event[0][1])
|
||||||
|
mnts = "0"+mnts if len(mnts) != 2 else mnts
|
||||||
|
subprocess.call(["notify-send", s, "At "+hrs+":"+mnts+" - "+event[1]])
|
||||||
|
|
||||||
|
startups = []; times = []
|
||||||
|
|
||||||
|
while True:
|
||||||
|
currtime = convert(time.strftime("%H:%M"))
|
||||||
|
events = [l.strip() for l in get(["calcurse", "-a"]).splitlines()][1:]
|
||||||
|
# arrange event data:
|
||||||
|
groups = []; sub = []
|
||||||
|
for l in events:
|
||||||
|
if l.startswith("* "):
|
||||||
|
groups.append([l.replace("* ", "")])
|
||||||
|
elif l.startswith("- "):
|
||||||
|
sub.append(convert(l.split("->")[0].replace("-", "").strip()))
|
||||||
|
else:
|
||||||
|
groups.append(sub+[l])
|
||||||
|
sub = []
|
||||||
|
# run notifications
|
||||||
|
for item in groups:
|
||||||
|
# on startup:
|
||||||
|
if not item in startups:
|
||||||
|
# all- day events
|
||||||
|
if len(item) == 1:
|
||||||
|
subprocess.call(["notify-send", "Today - "+item[0]])
|
||||||
|
# time- specific events
|
||||||
|
elif len(item) == 2:
|
||||||
|
show_time(item, "Appointment")
|
||||||
|
startups.append(item)
|
||||||
|
# as a reminder:
|
||||||
|
if all([len(item) == 2, not item in times]):
|
||||||
|
span = calc_diff(currtime, item[0])
|
||||||
|
if span <= warn:
|
||||||
|
show_time(item, "[Reminder]")
|
||||||
|
times.append(item)
|
||||||
|
# clean up events
|
||||||
|
startups = cleanup(startups, groups); times = cleanup(times, groups)
|
||||||
|
time.sleep(30)
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue