- This topic has 30 replies, 7 voices, and was last updated Jan 21-3:19 pm by Brian Masinick.
-
AuthorPosts
-
December 31, 2020 at 9:33 am #48621Member
PPC
I’ve been using yad-calendar as a simple agenda for a while, but recently I upgraded it, and now it pops open a yad window to enter a new description for the selected day, or edit exiting descriptions.
To use it, double click any day of the current month.
It’s a very basic agenda, without alarms and limited (not really, but in practice, yes) to a single line of text…#!/bin/bash ################################ Adicionar_evento(){ # Dia sem evento, adicionar um... event=$(yad --width=800 --form --center --title="Calendar: $day ..." --field="") && event=${event%|*} space=" " text=$day$space$event echo $text >> $HOME/yad-calendar.txt exit } Editar_evento(){ # Dia com evento já existente entrada=$(grep -h $day $HOME/yad-calendar.txt) line=($(grep -n $day $HOME/yad-calendar.txt | head -n 1 | cut -d: -f1)) altered_entry=$(yad --width=800 --center --title="Editar evento existente" --undecorated --form --field="" "$entrada") #retirar ultima letra, desnecessária entry=${altered_entry%|*} #gravar texto na linha original: awk -v line=$line -v texto="$entry" 'NR=='line' {$0='texto'} { print }' $HOME/yad-calendar.txt > $HOME/yad-calendar.txt.TEMP cp $HOME/yad-calendar.txt.TEMP $HOME/yad-calendar.txt exit } import -f Adicionar_evento Editar_evento touch ~/yad-calendar.txt && [ -s ~/yad-calendar.txt ] || echo "28/06/2020 This is how yad-calendar entries work! Add ONLY ONE line per day, starting with the date. If nothing shows up in the calendar, try another date format like dd-mm-yyyy" > $HOME/yad-calendar.txt #ecrã principal day=$(yad --calendar --undecorated --mouse --details=$HOME/yad-calendar.txt --button="X":1) if [[ $foo -eq 1 ]]; then exit 1 fi #se não se seleccionou nenhum dia, sair simplesmente [ -z "$day" ] && exit #se dia seleccionado ver se tem conteudo prévio ou nao if grep -q $day $HOME/yad-calendar.txt; then Editar_evento else Adicionar_evento fiThe comments are in portuguese, but there is no text that needs to be localized in the script itself!
Edit: How to use this “yad-agenda”:
Call the script and double click any day of the currently displayed month (A day with a description will be shown in “bold”):
– If it has no discription, a small window will pop up, allowing you to add a description to that day.
– If the selected day already has a description, a pop up window (without any window decorations) will show the complete line that referes to that day, including the full date. If you press “cancel” you cancel that event and remove it’s entry. If you change the date in the begining of the line, you will move the event to that new date.
You can see the entire “agenda” and directly edit it using any text editor- it’s in your home file, under the name yad-calendar.txt (yeah, Skidoo, I like poluting my home folder 🙂 ).
You can add, to that file a line with comments, begining with “#”. For example:#Anniversaries 25/12/2020 baby Jesus #Holidays 01/01/2021 New year day; Hang over :-)etc
P.
- This topic was modified 2 years, 4 months ago by PPC.
- This topic was modified 2 years, 4 months ago by PPC.
- This topic was modified 2 years, 4 months ago by PPC.
December 31, 2020 at 7:31 pm #48658Anonymous
::[post removed]
Wow. I missed “yad-calendar” and had replied as though it was a help request about “yad ––calendar”
{facepalm}January 13, 2021 at 10:43 am #49715MemberRobin
::Hello PPC,
Just tested your script while translating it. Nice idea and good work, I think.Please check line 26 in this version
import -f Adicionar_evento Editar_evento
as well as in the most recent version I’ve got from marcelocripe. This line produces an error message only, since there is no import command in bash shellscript available. So it will get executed by ImageMagick instead, and produce an errormessage only.
import-im6.q16: unrecognized option '-f' @ error/import.c/ImportImageCommand/820.
I’m quite sure you simply can drop this line unless I am very much mistaken.
Greetings and best regards for the New Year
Robin.- This reply was modified 2 years, 3 months ago by Robin.
Windows is like a submarine. Open a window and serious problems will start.
January 13, 2021 at 4:03 pm #49736MemberPPC
::During the week-end and last night I updated yad-calendar even more, and localized all output to English:
Changes:
-New GUI to enter events in an “empty” new day.
–If you only enter the event’s description it will be considered an all day event.
–If you enter a start date it will show up with the prefix @ – example: “@ 12:00 Launch time”
–If you enter an end time, it will be displayed like this: “@ 12:00-13:00 Launch time”
-New GUI that shows day’s events, when user double click a day with one or more events ( “all day events” are displayed on the top of the page)
-New “experimental” GUI to search for events in the agenda (it’s case insensitive)
– I fixed the bug Robin noticed.To do’s:
– Confirm valid times and date
– I’m working in a GUI to add events to a day that already has events (instead of editing the day’s full line manually)- it’s almost done
– To finish off, I’m looking for a way to edit/remove entries from a day. Finding a way to move events to a new day would be ideal, but very troublessom…
– Find a nice script ( don’t want to right it from scratch) that runs on very little RAM and CPU ) to act as alarm, for the entries on the agenda- this would basically make yad-agenda a fully featured (yet basic and low on resources) Personal Agenda… – hey, even Linux Mint does not have an agenda on their calendar, so if the Dev’s pick this up, it would be a nice handy feature for those of us that don’t like to use google calendar on their phones…It’s all work in progress, but, I believe, quite usable as is…
#!/bin/bash ################################ Adicionar_evento () { # Dia sem evento, adicionar um... entrada=$(yad --title="Agenda" --center --form --field="Date::DT" --field="Start (optional):" --field="End (optional):" --field="Event:" "$day" "$hora_inicio" "$hora_fim" "$evento") data=$(echo $entrada |cut -d'|' -f1) inicio=$(echo $entrada |cut -d'|' -f2) [[ ! -z "$inicio" ]] && inicio=$(echo \@ $inicio) evento=$(echo $entrada |cut -d'|' -f4) fim=$(echo $entrada |cut -d'|' -f3) #adicionar indicação de fim de evento apenas se existir indicação de hora final [[ ! -z "$fim" ]] && inicio=$(echo $inicio-$fim) echo $data $inicio $evento >> $HOME/yad-calendar.txt exit } Editar_evento(){ # Dia com evento já existente export -f add_event_to_day #Criar tabela de eventos para o dia em causa entrada=$(grep -h $day $HOME/yad-calendar.txt) reminder_time=$(echo $entrada|cut -d' ' -f2) reminder_date=$(echo $entrada|cut -d' ' -f1) line=($(grep -n $day $HOME/yad-calendar.txt | head -n 1 | cut -d: -f1)) #grep $day $HOME/yad-calendar.txt |cut -d' ' -f1 --complement eventos_existentes=$(grep $day $HOME/yad-calendar.txt |cut -d' ' -f1 --complement) #eventos_existentes=$(echo \@ $eventos_existentes) echo $eventos_existentes x=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo The number of events for the day is $x let "x=x+2" #contar eventos após o primeiro (cada evento com hora é indicado pelo sinal de arroba (@) numero_de_eventos_no_dia=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo "" > /tmp/listar_eventos_do_dia i=1 until [ $i -ge $x ] do grep $day $HOME/yad-calendar.txt |cut -d@ -f$i >> /tmp/listar_eventos_do_dia ((i=i+1)) done #listar eventos do dia no yad: evento_a_editar=$(yad --title="Calendar - $day" --button="Manually edit day's events":1 --width=550 --height=550 --center --separator=" " --list --column="" < /tmp/listar_eventos_do_dia) foo=$? if [[ $foo -eq 1 ]]; then # Edit day- first version entrada=$(grep -h $day $HOME/yad-calendar.txt) line=($(grep -n $day $HOME/yad-calendar.txt | head -n 1 | cut -d: -f1)) altered_entry=$(yad --width=800 --center --title="Editar evento existente" --undecorated --form --field="" "$entrada") #retirar ultima letra, desnecessária entry=${altered_entry%|*} #gravar texto na linha original: #echo $altered_entry >> $HOME/yad-calendar.txt && geany $HOME/yad-calendar.txt #awk -v line=$line -v texto=$altered_entry 'NR=='line' {$0='"texto"'} { print }' $HOME/yad-calendar.txt > $HOME/yad-calendar.txt.TEMP awk -v line=$line -v texto="$entry" 'NR=='line' {$0='texto'} { print }' $HOME/yad-calendar.txt > $HOME/yad-calendar.txt.TEMP cp $HOME/yad-calendar.txt.TEMP $HOME/yad-calendar.txt exit fi ##TODO: #START future entry for real GUI to add event: if [[ $foo -eq 2 ]]; then ### para efeito de testes: indicar aqui o dia: data=$day inicio=$(echo $entrada |cut -d'|' -f2) [[ ! -z "$inicio" ]] && inicio=$inicio || inicio="" evento=$(echo $entrada |cut -d'|' -f4) fim=$(echo $entrada |cut -d'|' -f3) #adicionar indicação de fim de evento apenas se existir indicação de hora final [[ ! -z "$fim" ]] && fim=$(echo \(até às $fim\)) || fim="" echo " " $inicio $evento $fim >> /tmp/listar_eventos_do_dia sort /tmp/listar_eventos_do_dia > /tmp/nova_lista_eventos_do_dia ###Agora gravar lista de eventos do dia na linha correcta: day="13/01/2021" ##### Used to test GUI to add event to day with other events line=$day separator="@" cat /tmp/nova_lista_eventos_do_dia | while read F do line="${line} ${separator} ${F}" echo $line ENTRADA_ATUAL=$(egrep "^$day " $HOME/yad-calendar.txt) ENTRADA_NOVA=$line ###sed -i "/^$day/s/$ENTRADA_ATUAL/$day $ENTRADA_NOVA/g" $HOME/yad-calendar.txt done; exit fi ##END future entry for real GUI to add event } search_event(){ ###future entry to search for events: rm /tmp/agenda_search_results.txt event_to_search=$( yad --title="Search for event" --center --entry --entry-label="Search for days with this event:") grep -i $event_to_search ~/yad-calendar.txt > /tmp/agenda_search_results-desorganized.txt sort -t- -k3.1,3.4 -k2,2 /tmp/agenda_search_results-desorganized.txt > /tmp/agenda_search_results.txt yad --title="Calendar - Search results" --no-buttons --width=550 --height=550 --center --separator=" " --list --column="" < /tmp/agenda_search_results.txt pkill yad exit 1 } export -f Adicionar_evento Editar_evento search_event touch ~/yad-calendar.txt && [ -s ~/yad-calendar.txt ] || echo "28/06/2020 This is how yad-calendar entries work! Add ONLY ONE line per day, starting with the date. If nothing shows up in the calendar, try another date format like dd-mm-yyyy" > $HOME/yad-calendar.txt #ecrã principal day=$(yad --calendar --undecorated --mouse --details=$HOME/yad-calendar.txt --button="":"bash -c search_event" --button="X":1) if [[ $foo -eq 1 ]]; then pkill yad exit 1 fi if [[ $foo -eq 2 ]]; then exit fi #se não se seleccionou nenhum dia, sair simplesmente [ -z "$day" ] && exit #se dia seleccionado ver se tem conteudo prévio ou nao if grep -q $day $HOME/yad-calendar.txt; then Editar_evento else Adicionar_evento fi- This reply was modified 2 years, 3 months ago by PPC.
- This reply was modified 2 years, 3 months ago by PPC.
January 13, 2021 at 5:19 pm #49751MemberPPC
::I almost forgot, I wrote a companion script, to be added to the system’s startup file, that displays events for the current day, if there’s any (please note that’s not any kind of alarm).
There was a user, now probably on a very heavy Calendar program that asked exactly for this… It’s easier done than creating alarms… 🙂#!/bin/bash #Display todays events using data in $HOME/yad-calendar.txt, if there's any day=$(date +"%d"/"%m"/"%Y") entrada=$(grep -h $day $HOME/yad-calendar.txt) if test -z "$entrada" then echo "Nothing for today" else echo "Events found for today: $entrada" #Create table for todays events reminder_time=$(echo $entrada|cut -d' ' -f2) reminder_date=$(echo $entrada|cut -d' ' -f1) line=($(grep -n $day $HOME/yad-calendar.txt | head -n 1 | cut -d: -f1)) #grep $day $HOME/yad-calendar.txt |cut -d' ' -f1 --complement eventos_existentes=$(grep $day $HOME/yad-calendar.txt |cut -d' ' -f1 --complement) echo $eventos_existentes x=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo The number of events for the day is $x let "x=x+2" numero_de_eventos_no_dia=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo "" > /tmp/listar_eventos_do_dia i=1 until [ $i -ge $x ] do grep $day $HOME/yad-calendar.txt |cut -d@ -f$i >> /tmp/listar_eventos_do_dia ((i=i+1)) done #list todays events in a yad window: evento_a_editar=$(yad --title="Calendar - $day" --button="OK":1 --width=550 --height=550 --center --separator=" " --list --column="" < /tmp/listar_eventos_do_dia) fiEnjoy
P.January 14, 2021 at 8:44 pm #49860Member
oops
January 15, 2021 at 5:58 pm #49916MemberPPC
::Thanks for all input.
I have 2 good news: my yad-calendar interface is nearly completed, it looks and acts almost like a full blown calendar application! (The single thing still remaining is a GUI to delete existing entries AND check for validity of date and time).
Better yet- I developed, from scratch, a script, than runs on about 750 Kb of RAM, to monitor timed events that are in ~/yad-calender.txt file. Events there do not have to be entered via any GUI but do have to obey this simple rules:
– one day per line
– start with [date] (four digits for the year), a space, “@”, [time of event], space, [event description].
– there can be multiple timed events per day (but the date comes only on the start of the line):
Ex: “15/01/2021 @07:30 Wake up @09:00 arrive at work @12:30 leave for lunch @18:45 Go home”Note: you can have an all day event just after the date, before, the first “@”, it will be ignored…
EX: “25/12/2021 Christmas @22:30 Open presents”Save the script, make it executable (I call it yad-calendar-alarm.sh) and place it in your startup file (ex: (without commas) “~/yad-calendar-alarm.sh &”)
It runs on 750Kb of RAM all the time, it doubles that value every 30 seconds to check for new events. RAM use is negligible, even on my single core CPU…The “alarm” script, it’s still a BETA, please test carefully, it’s not for mainstream use yet:
#!/bin/bash ### alarme sound from de https://unix.stackexchange.com/questions/1974/how-do-i-make-my-pc-speaker-beep pkill $BASH_SOURCE killall sleep today=$(date '+%d/%m/%Y') #read alarm and event from file eventos_existentes=$(grep $today $HOME/yad-calendar.txt |cut -d' ' -f1 --complement) echo $eventos_existentes x=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo The number of events for the day is $x let "x=x+2" #Count events (one per each @) numero_de_eventos_no_dia=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo "" > /tmp/listar_eventos_do_dia i=2 until [ $i -ge $x ] do #grep $day $HOME/yad-calendar.txt |cut -d@ -f$i >> /tmp/listar_eventos_do_dia grep $today $HOME/yad-calendar.txt |cut -d@ -f$i |cut -d" " -f1 target_time=$(grep $today $HOME/yad-calendar.txt |cut -d@ -f$i |cut -d" " -f1) event_description=$(grep $today $HOME/yad-calendar.txt |cut -d@ -f$i |cut -d" " -f2) initial_time=$(date +"%H":"%M":"%S") diference=$(echo "$target_time $initial_time" | (read later_time; read former_time; former_seconds=$(date --date="$former_time" +%s); later_seconds=$(date --date="$later_time" +%s); echo $((later_seconds-former_seconds)) )) nohup sleep $diference && yad --center --width=300 --no-buttons --window-icon="/usr/share/icons/papirus-antix/22x22/apps/calendar.png" --title="antiX Calendar" --text="\n $target_time - $event_description \n" --text-align=center & speaker-test --frequency 200 --test sine & sleep 2 && pkill speaker-test echo Alarm will sound in $diference seconds ((i=i+1)) done sleep 30 && $BASH_SOURCE &- This reply was modified 2 years, 3 months ago by PPC.
January 15, 2021 at 6:50 pm #49917Moderator
Brian Masinick
::@PPC: Thank you very much for your efforts in creating these tools.
By sharing them, people can either:
– use them as is, and benefit from a light, simple, easy to use tool
– use the idea, but modify it slightly to suit their own personal tastes and preferences
– learn from the straightforward code that you have written, and use it to create their own tools for the same or other purposesWhether people do this, something else, or just use “standard tools” I feel that this kind of sharing and discussion is healthy and promotes more learning and sharing. Once again, thank you very much for all of your thoughtful, useful contributions!
--
Brian MasinickJanuary 16, 2021 at 12:17 am #49952MemberPPC
::Very nearly completed (and fully functional) version of yad-calendar (I rebranded it “antiX Calendar”)
Changelog:
-I now use a variable, in the start of the script, to select the calendar text file. If you want to change the file, or file path, just edit it
– GUI’s to add/cancel events (timed and all day events) to empty days, days with events.
– Use icons and window name in all yad windows
– Interface and comments should be fully localized to English
– I changed the event input window’s to a more logical and faster to use layout
– Cleaned up the code a bit
– The script now looks more polished
– Used with the previous companion scripts, this is almost a fully fledged calendar, with alarms, etc.TODO’s:
– Validate date and time fields
– Clean up the code even more
– Integrate the companion scripts with the main antiX calendar script (they can be used with cli options, example: “antix-calendar –alarm” to activate alarms, “antix-calendar –today” to display the day’s events at start up.
– Think of a way to add recurring events (at least annually, it’s handy for birthdays and holidays)
– Add a way to edit results of the “search window”
– If a better “coder” than me want to help with bugs/missing features (and ideally add import/export function to the calendar’s file), all help is welcomeNot a bug, but features:
If you edit the “date” field of a day with events and remove it, that will erase the entire day’s contents
I kept the original “manually edit day” button because it can be handy to manually edit many events in a day, instead of clicking through the GUI- but that can be subjected to change- the user can always edit the calendar text file in a text editor… I kept it there also to quickly fix and bugs left on the edited day.BUGS:
-No validation of date and time: just like in a pen and paper agenda, you can enter “31/02/9999 @25:79 Just noticed I’m dislexic”… Because of that, you can add an event to a day with previous events, without a date. It will come up as “16/01/2021 @I messed up”- the correct way to add an all day event is clicking the date, on the top of the day’s window and edit the day’s field.
-If you add a new event to a day with events, that entry is sorted and inserted on the correct place, but, if you edit a timed event and change it’s time, it will not get sorted out, and will remain out of place, if you change it to a time previous or post other event’s time… I’m too tired to solve that one for now, it’s not serious, but I dislike bugs…@Robin: sorry, as you can see I was in the process of heavily reworking my code, and did not reply, I’ll try to PM you tomorrow…
#!/bin/bash #Simple antiX Calendar. Dependencies: Yad. By PPC, GPL license, 15/01/2021. Please keep this line about Creator and license export calendar_file="$HOME/yad-calendar.txt" window_icon=/usr/share/icons/papirus-antix/22x22/apps/calendar.png #Remove empty lines sed -i '/^$/d' $calendar_file #Remove empty "@@" sed -i -e 's/\@\@/\@/g' $calendar_file #Remove space after @ (replace "@ " with "@") sed -i -e 's/\@ /\@/g' $calendar_file Adicionar_evento () { # Empty day, add an event entrada=$(yad --window-icon=$window_icon --title="$day" --center --form --field="Event:" --field="Start (optional):" --field="End (optional):") inicio=$(echo $entrada |cut -d'|' -f2) [[ ! -z "$inicio" ]] && inicio=$(echo \@ $inicio) evento=$(echo $entrada |cut -d'|' -f1) fim=$(echo $entrada |cut -d'|' -f3) #Add indication of end of event only if "end" was inputed [[ ! -z "$fim" ]] && inicio=$(echo $inicio-$fim) echo $day $inicio $evento >> $HOME/yad-calendar.txt exit } Editar_evento(){ # Day with existing event(s) #Create array of the day's event(s) entrada=$(grep -h $day $calendar_file) reminder_time=$(echo $entrada|cut -d' ' -f2) reminder_date=$(echo $entrada|cut -d' ' -f1) line=($(grep -n $day $calendar_file | head -n 1 | cut -d: -f1)) eventos_existentes=$(grep $day $calendar_file |cut -d' ' -f1 --complement) #Count existing timed events (indicated by "@", so, count "@" signs x=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo The number of events for the day is $x let "x=x+2" numero_de_eventos_no_dia=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') #clean temporary file echo "" > /tmp/listar_eventos_do_dia ##loop to check for each timed event, add each event to a different line of the temp file i=1 until [ $i -ge $x ] do grep $day $calendar_file |cut -d@ -f$i >> /tmp/listar_eventos_do_dia ((i=i+1)) done #remove empty lines sed -i '/^$/d' /tmp/listar_eventos_do_dia #list that day's event(s) in a yad window: evento_a_editar=$(yad --window-icon=$window_icon --title="$day" --button="Manually edit day's events !/usr/share/icons/papirus-antix/22x22/actions/document-edit.png":1 --button="+":2 --width=550 --height=550 --center --separator=" " --list --column="Double click an event to edit or cancel it, double click date to add an all day event" < /tmp/listar_eventos_do_dia) foo=$? echo Selected: $evento_a_editar if [[ $foo -eq 1 ]]; then # Edit day- original first version entrada=$(grep -h $day $calendar_file) line=($(grep -n $day $calendar_file | head -n 1 | cut -d: -f1)) altered_entry=$(yad --width=800 --center --title="Edit event" --undecorated --form --field="" "$entrada") #Remove unneded trailing character entry=${altered_entry%|*} #Save back text in the original line: awk -v line=$line -v texto="$entry" 'NR=='line' {$0='texto'} { print }' $calendar_file > $calendar_file.TEMP cp $calendar_file.TEMP $calendar_file #Remove empty lines sed -i '/^$/d' $calendar_file #remove space after @ (replace "@ " with "@") sed -i -e 's/\@ /\@/g' $calendar_file exit fi #START GUI to add (timed) event: if [[ $foo -eq 2 ]]; then #Clear temporary files echo > /tmp/listar_eventos_do_dia echo > /tmp/nova_linha.txt echo > /tmp/nova_lista_eventos_do_dia #Generate list of current day's events (withouy all day events), in file /tmp/listar_eventos_do_dia eventos_existentes=$(grep ^$day $calendar_file |cut -d' ' -f1 --complement) echo $eventos_existentes x=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo O Numero de Eventos no dia em causa é $x let "x=x+2" #Count envents (each @ sign) numero_de_eventos_no_dia=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo "" > /tmp/listar_eventos_do_dia i=2 #loop to add events to temporary file until [ $i -ge $x ] do grep $day $calendar_file |cut -d@ -f$i >> /tmp/listar_eventos_do_dia ((i=i+1)) done #Remove empty lines sed -i '/^$/d' /tmp/listar_eventos_do_dia #get new entry to be added to day, using a yad window entrada=$(yad --window-icon=$window_icon --title="$day" --center --form --field="Event" --field=Start --field="End (optional)") #process result of user entry: data=$day inicio=$(echo $entrada |cut -d'|' -f2) [[ ! -z "$inicio" ]] && inicio=$inicio || inicio="" ##if [ -z "$evento" ] ##then ## echo No event entered ## exit 1 ## else evento=$(echo $entrada |cut -d'|' -f1) ##fi fim=$(echo $entrada |cut -d'|' -f3) ##Add end time only if inputed ##[[ ! -z "$fim" ]] && fim=$(echo \(- $fim\)) || fim="" echo $inicio $evento $fim >> /tmp/listar_eventos_do_dia echo New entry to be added to $day: cat /tmp/listar_eventos_do_dia ####Put events in correct order date_and_all_day_events=$(egrep "^$day " $calendar_file |cut -d'@' -f1) sort /tmp/listar_eventos_do_dia > /tmp/temp0.txt tac /tmp/temp0.txt > /tmp/temp1.txt echo $date_and_all_day_events >> /tmp/temp1.txt tac /tmp/temp1.txt > /tmp/listar_eventos_do_dia_editados sed -i '/^$/d' /tmp/listar_eventos_do_dia_editados # New event's list, starting with date (and eventual all day's events) followed by timed events, in /tmp/listar_eventos_do_dia_editados ###Create line from /tmp/listar_eventos_do_dia_editados #Start by adding " @" at the begining of each line sed -i -e 's/^/ @/' /tmp/listar_eventos_do_dia_editados #Remove " @" from first line (date and eventual all day events)- it's the 2 first characters, so, repeat sed command sed -i '1s/^.//' /tmp/listar_eventos_do_dia_editados sed -i '1s/^.//' /tmp/listar_eventos_do_dia_editados #Generate line from temporary file export linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) echo "Current day's entry will be:" echo $linha_nova ###Save changes in correct day export day export ENTRADA_ATUAL=$(egrep "^$day " $calendar_file) while read -r line; do linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) printf "%s\n" "${line/"${ENTRADA_ATUAL}"/"${linha_nova}"}" done < $calendar_file > ~/file.new cp ~/file.new $calendar_file echo Generated entry for $day is egrep "^$day " $calendar_file #remove empty lines sed -i '/^$/d' $calendar_file #remove empty "@@" sed -i -e 's/\@\@/\@/g' $calendar_file #remove space after @ (replace "@ " with "@") sed -i -e 's/\@ /\@/g' $calendar_file exit fi ##END of GUI to add (timed) event ### Process click in event from list: entrada=$(grep -h $day $calendar_file) echo Entrada completa a ser editada: echo $entrada echo Evento a editar: echo $evento_a_editar if [ -z "${evento_a_editar}" ]; then echo "No event selected for edition, exiting" exit fi input=$evento_a_editar echo $input > /tmp/tempor1 evento_a_editar=$(cat /tmp/tempor1 |cut -d'|' -f1) input2=$(yad --window-icon=$window_icon --center --title="$day" --form --field="" "$evento_a_editar") echo $input2 > /tmp/tempor2 alteracao=$(cat /tmp/tempor2 |cut -d'|' -f1) echo Alteração: echo $alteracao echo Resultado final, a editar no texto: export result=$(echo $entrada | awk -v srch="$evento_a_editar" -v repl="$alteracao" '{ sub(srch,repl,$0); print $0 }') echo $result echo Fim do processo ###Save changes in correct day export day export ENTRADA_ATUAL=$(egrep "^$day " $calendar_file) while read -r line; do linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) printf "%s\n" "${line/"${ENTRADA_ATUAL}"/"${result}"}" done < $calendar_file > ~/file.new egrep "^$day " ~/file.new cp ~/file.new $calendar_file egrep "^$day " $calendar_file #remove empty lines sed -i '/^$/d' $calendar_file #remove empty "@@" sed -i -e 's/\@\@/\@/g' $calendar_file #remove space after @ (replace "@ " with "@") sed -i -e 's/\@ /\@/g' $calendar_file } search_event(){ ###future entry to search for events: rm /tmp/agenda_search_results.txt event_to_search=$( yad --window-icon=$window_icon --title="antiX Calendar" --center --entry --entry-label="" --button=" !/usr/share/icons/papirus-antix/22x22/actions/search.png") grep -i $event_to_search $calendar_file > /tmp/agenda_search_results-desorganized.txt sort -t- -k3.1,3.4 -k2,2 /tmp/agenda_search_results-desorganized.txt > /tmp/agenda_search_results.txt yad --window-icon=$window_icon --title="antiX Calendar - Search results" --no-buttons --width=550 --height=550 --center --separator=" " --list --column="" < /tmp/agenda_search_results.txt pkill yad exit 1 } export -f Adicionar_evento Editar_evento search_event touch $calendar_file && [ -s $calendar_file ] || echo "28/06/2020 This is how yad-calendar entries work! Add ONLY ONE line per day, starting with the date. If nothing shows up in the calendar, try another date format like dd-mm-yyyy" > $calendar_file #Main window day=$(yad --window-icon=$window_icon --title="antiX Calendar" --calendar --undecorated --mouse --details=$calendar_file --button=" !/usr/share/icons/papirus-antix/22x22/actions/search.png":"bash -c search_event" --button="X":1) if [[ $foo -eq 1 ]]; then pkill yad exit 1 fi if [[ $foo -eq 2 ]]; then exit fi #Exit if no day was selected [ -z "$day" ] && exit #If a day was selected, check if it has any events (a line starting with a date) if grep -q $day $calendar_file; then Editar_evento else Adicionar_evento fi- This reply was modified 2 years, 3 months ago by PPC.
January 16, 2021 at 2:53 am #49963Member
sleekmason
::Very nicely done. Thank you for posting your work. I am certainly going to use your script instead of the calendar I’ve been using. Thank you. Looking forward to your future updates:)
January 16, 2021 at 2:51 pm #49977MemberPPC
::For some reason, all the examples I found on-line about validating time in a bash script never quite worked out, and I ended up devoleping one myself.
The script now checks validity of start time of events (both the ones added to empty days and days with more events), but the time of the event’s “end” is not validated.
since I wrote the validation script from scrach, it’s “smart”: you can enter “9:15” and it gets corrected to “09:15”.Unfortunatly I’m losing my momentum… Because the script already works quite well, I won’t change it much, maybe try to merge the 2 auxiliary scripts with each other and with the main “antiX Calendar” one.
Changelog:
– Validation of event’s start time
– Fixed regression that stopped to have more than one timed event per day (it was a bug in the clean up part of the script)TODO’s/BUGS:
– Still, if you change an event’s time, it is not automaticaly sorted out… It’s a minor problem, but an anoying oneThe current version:
#!/bin/bash #Simple Calendar for antiX - dependencies: Yad. By PPC, GPL license, 15/01/2021. Please keep this line about Creator and license export calendar_file="$HOME/yad-calendar.txt" window_icon=/usr/share/icons/papirus-antix/22x22/apps/calendar.png ##Clean up calendar file (NOTE: because @ is a special character, in order for the sed comand to percieve it as an ordinary character, it has to be preceded by \, like so: "\@"): #Remove all empty lines sed -i '/^$/d' $calendar_file #Remove lines with only date and nothing more (orphan lines)- it removes all lines with less than 10 characters sed -i -r '/^.{,10}$/d' $calendar_file #Replace "@@" with a simple "@" sed -i -e 's/\@\@/\@/g' $calendar_file #Replace "@ @" with "@" sed -i -e 's/\@ \@/\@/g' $calendar_file #Remove any "@" left at the end of any line sed 's/\@$//' $calendar_file Check_time () { #Validate inputed time time=$1 export time_check="good" export hour=$(echo $time |cut -d':' -f1) export number_of_digits_in_hour=$(echo -n "$hour" | wc -c) ##echo $number_of_digits_in_hour if [ "$number_of_digits_in_hour" -lt 2 ] ; then hour=$(echo 0$hour) fi if [ "$hour" -lt 24 ] ; then echo "Valid hour" #hour is ok, checking minutes minute=$(echo $time |cut -d':' -f2) number_of_digits_in_minute=$(echo -n "$minute" | wc -c) # echo $number_of_digits_in_minute if [ "$number_of_digits_in_minute" -lt 2 ] ; then hour=$(echo 0$minute) fi if [ "$minute" -lt 60 ] ; then echo "Valid minute" else ## echo "InValid time pattern" export time_check="bad" fi else ## echo "InValid time pattern" export time_check="bad" fi echo $time } Adicionar_evento () { # Empty day, add an event export -f Check_time entrada=$(yad --window-icon=$window_icon --title="$day" --center --form --field="Event:" --field="Start (optional):" --field="End (optional):" "$evento" "$inicio" "") echo Selected: $evento_a_editar export inicio=$(echo $entrada |cut -d'|' -f2) export evento=$(echo $entrada |cut -d'|' -f1) export fim=$(echo $entrada |cut -d'|' -f3) Check_time $inicio #Check_time $fim if [ $time_check == "bad" ] then echo "time not ok " yad --center --window-icon=$window_icon --title="antiX Calendar" --text=" Incorrect time entered \n Enter a time between 00:00 and 23:59 " --button="X":1 --button="OK":2 foo=$? if [[ $foo -eq 1 ]]; then exit fi if [[ $foo -eq 2 ]]; then inicio=$(echo $inicio |cut -d' ' -f2) fim=$(echo $inicio |cut -d' ' -f3) Adicionar_evento fi fi #add "@" before the start time [[ ! -z "$inicio" ]] && inicio=$(echo \@ $inicio) #Add indication of end of event only if "end" was inputed [[ ! -z "$fim" ]] && inicio=$(echo $inicio-$fim) #Save entered data to file echo $day $inicio $evento >> $HOME/yad-calendar.txt exit } Editar_evento(){ # Day with existing event(s) #Create array of the day's event(s) entrada=$(grep -h $day $calendar_file) reminder_time=$(echo $entrada|cut -d' ' -f2) reminder_date=$(echo $entrada|cut -d' ' -f1) line=($(grep -n $day $calendar_file | head -n 1 | cut -d: -f1)) eventos_existentes=$(grep $day $calendar_file |cut -d' ' -f1 --complement) #Count existing timed events (indicated by "@", so, count "@" signs x=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo The number of events for the day is $x let "x=x+2" numero_de_eventos_no_dia=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') #clean temporary file echo "" > /tmp/listar_eventos_do_dia ##loop to check for each timed event, add each event to a different line of the temp file i=1 until [ $i -ge $x ] do grep $day $calendar_file |cut -d@ -f$i >> /tmp/listar_eventos_do_dia ((i=i+1)) done #remove empty lines sed -i '/^$/d' /tmp/listar_eventos_do_dia #list that day's event(s) in a yad window: evento_a_editar=$(yad --window-icon=$window_icon --title="$day" --button="+":2 --width=550 --height=550 --center --separator=" " --list --column="Double click an event to edit or cancel it, double click date to add an all day event" < /tmp/listar_eventos_do_dia) foo=$? echo Selected: $evento_a_editar #Removed button to manually edit days's events from the previous yad command: #--button="Manually edit day's events !/usr/share/icons/papirus-antix/22x22/actions/document-edit.png":1 if [[ $foo -eq 1 ]]; then # Edit day- original first version entrada=$(grep -h $day $calendar_file) line=($(grep -n $day $calendar_file | head -n 1 | cut -d: -f1)) altered_entry=$(yad --width=800 --center --title="Edit event" --undecorated --form --field="" "$entrada") #Remove unneded trailing character entry=${altered_entry%|*} #Save back text in the original line: awk -v line=$line -v texto="$entry" 'NR=='line' {$0='texto'} { print }' $calendar_file > $calendar_file.TEMP cp $calendar_file.TEMP $calendar_file exit fi #START GUI to add (timed) event: if [[ $foo -eq 2 ]]; then #Clear temporary files echo > /tmp/listar_eventos_do_dia echo > /tmp/nova_linha.txt echo > /tmp/nova_lista_eventos_do_dia #Generate list of current day's events (withouy all day events), in file /tmp/listar_eventos_do_dia eventos_existentes=$(grep ^$day $calendar_file |cut -d' ' -f1 --complement) echo $eventos_existentes x=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo O Numero de Eventos no dia em causa é $x let "x=x+2" #Count envents (each @ sign) numero_de_eventos_no_dia=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo "" > /tmp/listar_eventos_do_dia i=2 #loop to add events to temporary file until [ $i -ge $x ] do grep $day $calendar_file |cut -d@ -f$i >> /tmp/listar_eventos_do_dia ((i=i+1)) done #Remove empty lines sed -i '/^$/d' /tmp/listar_eventos_do_dia #get new entry to be added to day, using a yad window entrada=$(yad --window-icon=$window_icon --title="$day" --center --form --field="Event" --field=Start --field="End (optional)") #process result of user entry: data=$day inicio=$(echo $entrada |cut -d'|' -f2) [[ ! -z "$inicio" ]] && inicio=$inicio || inicio="" ##if [ -z "$evento" ] ##then ## echo No event entered ## exit 1 ## else evento=$(echo $entrada |cut -d'|' -f1) ##fi fim=$(echo $entrada |cut -d'|' -f3) Check_time $inicio if [ $time_check == "bad" ] then echo "time not ok " yad --center --window-icon=$window_icon --title="antiX Calendar" --text=" Incorrect time entered \n Enter a time between 00:00 and 23:59 " --button="X":1 --button="OK":2 foo=$? if [[ $foo -eq 1 ]]; then exit fi if [[ $foo -eq 2 ]]; then inicio=$(echo $inicio |cut -d' ' -f2) fim=$(echo $inicio |cut -d' ' -f3) Editar_evento fi fi ##Add end time only if inputed ##[[ ! -z "$fim" ]] && fim=$(echo \(- $fim\)) || fim="" echo $inicio $evento $fim >> /tmp/listar_eventos_do_dia echo New entry to be added to $day: cat /tmp/listar_eventos_do_dia ####Put events in correct order date_and_all_day_events=$(egrep "^$day " $calendar_file |cut -d'@' -f1) sort /tmp/listar_eventos_do_dia > /tmp/temp0.txt tac /tmp/temp0.txt > /tmp/temp1.txt echo $date_and_all_day_events >> /tmp/temp1.txt tac /tmp/temp1.txt > /tmp/listar_eventos_do_dia_editados sed -i '/^$/d' /tmp/listar_eventos_do_dia_editados # New event's list, starting with date (and eventual all day's events) followed by timed events, in /tmp/listar_eventos_do_dia_editados ###Create line from /tmp/listar_eventos_do_dia_editados #Start by adding " @" at the begining of each line sed -i -e 's/^/ @/' /tmp/listar_eventos_do_dia_editados #Remove " @" from first line (date and eventual all day events)- it's the 2 first characters, so, repeat sed command sed -i '1s/^.//' /tmp/listar_eventos_do_dia_editados sed -i '1s/^.//' /tmp/listar_eventos_do_dia_editados #Generate line from temporary file export linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) echo "Current day's entry will be:" echo $linha_nova ###Save changes in correct day export day export ENTRADA_ATUAL=$(egrep "^$day " $calendar_file) while read -r line; do linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) printf "%s\n" "${line/"${ENTRADA_ATUAL}"/"${linha_nova}"}" done < $calendar_file > ~/file.new cp ~/file.new $calendar_file echo Generated entry for $day is egrep "^$day " $calendar_file exit fi ##END of GUI to add (timed) event ### Process click in event from list: entrada=$(grep -h $day $calendar_file) echo Entrada completa a ser editada: echo $entrada echo Evento a editar: echo $evento_a_editar if [ -z "${evento_a_editar}" ]; then echo "No event selected for edition, exiting" exit fi input=$evento_a_editar echo $input > /tmp/tempor1 evento_a_editar=$(cat /tmp/tempor1 |cut -d'|' -f1) input2=$(yad --window-icon=$window_icon --center --title="$day" --form --field="" "$evento_a_editar") echo $input2 > /tmp/tempor2 alteracao=$(cat /tmp/tempor2 |cut -d'|' -f1) echo Alteração: echo $alteracao echo Resultado final, a editar no texto: export result=$(echo $entrada | awk -v srch="$evento_a_editar" -v repl="$alteracao" '{ sub(srch,repl,$0); print $0 }') echo $result echo Fim do processo ###Save changes in correct day export day export ENTRADA_ATUAL=$(egrep "^$day " $calendar_file) while read -r line; do linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) printf "%s\n" "${line/"${ENTRADA_ATUAL}"/"${result}"}" done < $calendar_file > ~/file.new egrep "^$day " ~/file.new cp ~/file.new $calendar_file egrep "^$day " $calendar_file } search_event(){ ###future entry to search for events: event_to_search=$( yad --window-icon=$window_icon --title="antiX Calendar" --center --entry --entry-label="" --button=" !/usr/share/icons/papirus-antix/22x22/actions/search.png") rm /tmp/agenda_search_results.txt grep -i $event_to_search $HOME/yad-calendar.txt > /tmp/agenda_search_results-desorganized.txt grep -i $event_to_search $HOME/yad-calendar.txt > /tmp/agenda_search_results-desorganized.txt sort -t- -k3.1,3.4 -k2,2 /tmp/agenda_search_results-desorganized.txt > /tmp/agenda_search_results.txt #Display results yad --window-icon=$window_icon --title="antiX Calendar" --no-buttons --width=550 --height=550 --center --separator=" " --list --column="" < /tmp/agenda_search_results.txt pkill yad exit 1 } export -f Adicionar_evento Editar_evento search_event Check_time touch $calendar_file && [ -s $calendar_file ] || echo "28/06/2020 This is how yad-calendar entries work! Add ONLY ONE line per day, starting with the date. If nothing shows up in the calendar, try another date format like dd-mm-yyyy" > $calendar_file #Main window day=$(yad --window-icon=$window_icon --title="antiX Calendar" --calendar --undecorated --mouse --details=$calendar_file --button=" !/usr/share/icons/papirus-antix/22x22/actions/search.png":"bash -c search_event" --button="X":1) if [[ $foo -eq 1 ]]; then pkill yad exit 1 fi if [[ $foo -eq 2 ]]; then exit fi #Exit if no day was selected [ -z "$day" ] && exit #If a day was selected, check if it has any events (a line starting with a date) if grep -q $day $calendar_file; then Editar_evento else Adicionar_evento fiPlease test the script and report any bugs/suggestion. Feel free to contribute, it was a very tiresome process, converting the simple yad-calendar to an agenda.
Disclamer:
Right now, the script if fully usable, in a final Beta level – feel free to use it, but do not rely on it for important appointments (I always use a pen and paper agenda, to be on the safe side, for all important stuff).P.
January 16, 2021 at 2:57 pm #49978Moderator
Brian Masinick
January 16, 2021 at 9:33 pm #49999MemberPPC
::Sigh… I found some regressions and was able to fix them, and also, dispite not wanting to do that, I had to partly repeat the code to always make sure the day’s contents are in order.
Also, along the way, a new regression- validating the time field does not work when adding events to days with other events…
For now, I have to take a rest… Time validation will have to wait…#!/bin/bash #Simple Calendar for antiX - dependencies: Yad. By PPC, GPL license, 15/01/2021. Please keep this line about Creator and license export calendar_file="$HOME/yad-calendar.txt" window_icon=/usr/share/icons/papirus-antix/22x22/apps/calendar.png ##Clean up calendar file (NOTE: because @ is a special character, in order for the sed comand to percieve it as an ordinary character, it has to be preceded by \, like so: "\@"): #Remove all empty lines sed -i '/^$/d' $calendar_file #Remove all empty lines sed -i '/^$/d' $calendar_file #Remove lines with only date and nothing more (orphan lines)- it removes all lines with less than 10 characters sed -i -r '/^.{,10}$/d' $calendar_file #Replace "@@" with a simple "@" sed -i -e 's/\@\@/\@/g' $calendar_file #Replace "@ @" with "@" sed -i -e 's/\@ \@/\@/g' $calendar_file #Remove any "@" left at the end of any line sed 's/\@$//' $calendar_file #Remove any "@ " left at the end of any line sed 's/\@ $//' $calendar_file Check_time () { #Validate time format time=$inicio number_of_digits_in_time=$(echo -n "time" | wc -c) export time_check="good" #Only procede if there's a initial time entered- to allow adding directly "all day events" #check is "time" value exists, store result in "time_inputed" [[ ! -z "$inicio" ]] && time_inputed=1 || time_inputed=0 if [ $time_inputed -eq 1 ];then echo "USer entered start time, it's not an all day event, check if time is valid" hour=$(echo $time |cut -d':' -f1) number_of_digits_in_hour=$(echo -n "$hour" | wc -c) ##echo $number_of_digits_in_hour if [ "$number_of_digits_in_hour" -lt 2 ] ; then hour=$(echo 0$hour) fi if [ "$hour" -lt 24 ] ; then echo "Valid time pattern" #hour is ok, checking minutes minute=$(echo $time |cut -d':' -f2) number_of_digits_in_minute=$(echo -n "$minute" | wc -c) ## echo $number_of_digits_in_minute if [ "$number_of_digits_in_minute" -lt 2 ] ; then hour=$(echo 0$minute) fi if [ "$minute" -lt 60 ] ; then echo "Valid time pattern" else ## echo "InValid time pattern" export time_check="bad" fi else ## echo "InValid time pattern" export time_check="bad" fi fi } Adicionar_evento () { # Empty day, add an event entrada=$(yad --window-icon=$window_icon --title="$day" --center --form --field="Event:" --field="Start (optional):" --field="End (optional):" "$evento" "$inicio" "") echo Selected: $evento_a_editar export inicio=$(echo $entrada |cut -d'|' -f2) evento=$(echo $entrada |cut -d'|' -f1) export fim=$(echo $entrada |cut -d'|' -f3) Check_time inicio if [ $time_check == "bad" ] then echo "time not ok " yad --center --window-icon=$window_icon --title="antiX Calendar" --text=" Incorrect time entered \n Enter a time between 00:00 and 23:59 " --button="X":1 --button="OK":2 foo=$? if [[ $foo -eq 1 ]]; then exit fi if [[ $foo -eq 2 ]]; then inicio=$(echo $inicio |cut -d' ' -f2) fim=$(echo $inicio |cut -d' ' -f3) Adicionar_evento fi fi #add "@" before the start time [[ ! -z "$inicio" ]] && inicio=$(echo \@ $inicio) #Add indication of end of event only if "end" was inputed [[ ! -z "$fim" ]] && inicio=$(echo $inicio-$fim) #Save entered data to file echo $day $inicio $evento >> $HOME/yad-calendar.txt exit } Editar_evento(){ # Day with existing event(s) #Create array of the day's event(s) entrada=$(grep -h $day $calendar_file) reminder_time=$(echo $entrada|cut -d' ' -f2) reminder_date=$(echo $entrada|cut -d' ' -f1) line=($(grep -n $day $calendar_file | head -n 1 | cut -d: -f1)) eventos_existentes=$(grep $day $calendar_file |cut -d' ' -f1 --complement) #Count existing timed events (indicated by "@", so, count "@" signs x=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo The number of events for the day is $x let "x=x+2" numero_de_eventos_no_dia=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') #clean temporary file echo "" > /tmp/listar_eventos_do_dia ##loop to check for each timed event, add each event to a different line of the temp file i=1 until [ $i -ge $x ] do grep $day $calendar_file |cut -d@ -f$i >> /tmp/listar_eventos_do_dia ((i=i+1)) done #remove empty lines sed -i '/^$/d' /tmp/listar_eventos_do_dia #list that day's event(s) in a yad window: evento_a_editar=$(yad --window-icon=$window_icon --title="$day" --button="+":2 --width=550 --height=550 --center --separator=" " --list --column="Double click an event to edit or cancel it, double click date to add an all day event" < /tmp/listar_eventos_do_dia) foo=$? echo Selected: $evento_a_editar #START GUI to add (timed) event: if [[ $foo -eq 2 ]]; then #process result of user entry: date=$day input=$(yad --window-icon=$window_icon --title="$day" --center --form --field="Event" --field=Start --field="End (optional)") export start=$(echo $input |cut -d'|' -f2) event=$(echo $input |cut -d'|' -f1) export end=$(echo $input |cut -d'|' -f3) ##### TO DO - time validation not working here!!!!!!!!!!!!!!!1 Check_time $start if [ $time_check == "bad" ] then echo "time not ok " yad --center --window-icon=$window_icon --title="antiX Calendar" --text=" Incorrect time entered \n Enter a time between 00:00 and 23:59 " --button="X":1 --button="OK":2 foo=$? if [[ $foo -eq 1 ]]; then exit fi if [[ $foo -eq 2 ]]; then Editar_evento fi fi edited_day=$(echo $current_day @$start $event) #Generate list of current day's events (withouy all day events), in file /tmp/listar_eventos_do_dia eventos_existentes=$(grep ^$day $calendar_file |cut -d' ' -f1 --complement) echo $eventos_existentes x=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo O Numero de Eventos no dia em causa é $x let "x=x+2" #Count envents (each @ sign) numero_de_eventos_no_dia=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo "" > /tmp/listar_eventos_do_dia i=2 #loop to add events to temporary file until [ $i -ge $x ] do grep $day $calendar_file |cut -d@ -f$i >> /tmp/listar_eventos_do_dia ((i=i+1)) done #Remove empty lines sed -i '/^$/d' /tmp/listar_eventos_do_dia #add new entry to the end of the file echo $edited_day >> /tmp/listar_eventos_do_dia ####Put events in correct order date_and_all_day_events=$(egrep "^$day " $calendar_file |cut -d'@' -f1) sort /tmp/listar_eventos_do_dia > /tmp/temp0.txt tac /tmp/temp0.txt > /tmp/temp1.txt echo $date_and_all_day_events >> /tmp/temp1.txt tac /tmp/temp1.txt > /tmp/listar_eventos_do_dia_editados sed -i '/^$/d' /tmp/listar_eventos_do_dia_editados # New event's list, starting with date (and eventual all day's events) followed by timed events, in /tmp/listar_eventos_do_dia_editados ###Create line from /tmp/listar_eventos_do_dia_editados #Start by adding " @" at the begining of each line sed -i -e 's/^/ @/' /tmp/listar_eventos_do_dia_editados #Remove " @" from first line (date and eventual all day events)- it's the 2 first characters, so, repeat sed command sed -i '1s/^.//' /tmp/listar_eventos_do_dia_editados sed -i '1s/^.//' /tmp/listar_eventos_do_dia_editados #Generate line from temporary file export linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) echo "Current day's entry will be:" echo $linha_nova ###Save changes in correct day export day export ENTRADA_ATUAL=$(egrep "^$day " $calendar_file) while read -r line; do linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) printf "%s\n" "${line/"${ENTRADA_ATUAL}"/"${linha_nova}"}" done < $calendar_file > ~/file.new #Replace "@@" with a simple "@" sed -i -e 's/\@\@/\@/g' ~/file.new cat ~/file.new cp ~/file.new $calendar_file echo Generated entry for $day is egrep "^$day " $calendar_file exit fi ##END of GUI to add (timed) event ### Process click in event from list: entrada=$(grep -h $day $calendar_file) echo Entrada completa a ser editada: echo $entrada echo Evento a editar: echo $evento_a_editar if [ -z "${evento_a_editar}" ]; then echo "No event selected for edition, exiting" exit fi input=$evento_a_editar echo $input > /tmp/tempor1 evento_a_editar=$(cat /tmp/tempor1 |cut -d'|' -f1) input2=$(yad --window-icon=$window_icon --center --title="$day" --form --field="" "$evento_a_editar") echo $input2 > /tmp/tempor2 alteracao=$(cat /tmp/tempor2 |cut -d'|' -f1) echo Alteração: echo $alteracao echo Resultado final, a editar no texto: export result=$(echo $entrada | awk -v srch="$evento_a_editar" -v repl="$alteracao" '{ sub(srch,repl,$0); print $0 }') echo $result echo Fim do processo ###Save changes in correct day export day export ENTRADA_ATUAL=$(egrep "^$day " $calendar_file) while read -r line; do linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) printf "%s\n" "${line/"${ENTRADA_ATUAL}"/"${result}"}" done < $calendar_file > ~/file.new egrep "^$day " ~/file.new cp ~/file.new $calendar_file #Replace "@ @" with "@" sed -i -e 's/\@ \@/\@/g' $calendar_file #Replace "@ " with "@" sed -i -e 's/\@ /\@/g' $calendar_file #Remove any "@" left at the end of any line sed 's/\@$//' $calendar_file #Remove any "@ " left at the end of any line sed 's/\@ $//' $calendar_file egrep "^$day " $calendar_file #####Ugly way to to reorder day's entries: #Generate list of current day's events (withouy all day events), in file /tmp/listar_eventos_do_dia eventos_existentes=$(grep ^$day $calendar_file |cut -d' ' -f1 --complement) echo $eventos_existentes x=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo O Numero de Eventos no dia em causa é $x let "x=x+2" #Count envents (each @ sign) numero_de_eventos_no_dia=$(tr -dc '@' <<<"$eventos_existentes" | awk '{ print length; }') echo "" > /tmp/listar_eventos_do_dia i=2 #loop to add events to temporary file until [ $i -ge $x ] do grep $day $calendar_file |cut -d@ -f$i >> /tmp/listar_eventos_do_dia ((i=i+1)) done #Remove empty lines sed -i '/^$/d' /tmp/listar_eventos_do_dia ####Put events in correct order date_and_all_day_events=$(egrep "^$day " $calendar_file |cut -d'@' -f1) sort /tmp/listar_eventos_do_dia > /tmp/temp0.txt tac /tmp/temp0.txt > /tmp/temp1.txt echo $date_and_all_day_events >> /tmp/temp1.txt tac /tmp/temp1.txt > /tmp/listar_eventos_do_dia_editados sed -i '/^$/d' /tmp/listar_eventos_do_dia_editados ###Create line from /tmp/listar_eventos_do_dia_editados #Start by adding " @" at the begining of each line sed -i -e 's/^/ @/' /tmp/listar_eventos_do_dia_editados #Remove " @" from first line (date and eventual all day events)- it's the 2 first characters, so, repeat sed command sed -i '1s/^.//' /tmp/listar_eventos_do_dia_editados sed -i '1s/^.//' /tmp/listar_eventos_do_dia_editados #Generate line from temporary file export linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) echo "Current day's entry will be:" echo $linha_nova ###Save changes in correct day export day export ENTRADA_ATUAL=$(egrep "^$day " $calendar_file) while read -r line; do linha_nova=$(tr -d '\n' < /tmp/listar_eventos_do_dia_editados) printf "%s\n" "${line/"${ENTRADA_ATUAL}"/"${linha_nova}"}" done < $calendar_file > ~/file.new #Replace "@@" with a simple "@" sed -i -e 's/\@\@/\@/g' ~/file.new cat ~/file.new cp ~/file.new $calendar_file echo Generated entry for $day is egrep "^$day " $calendar_file exit ##END } search_event(){ ###search for events: event_to_search=$( yad --window-icon=$window_icon --title="antiX Calendar" --center --entry --entry-label="" --button=" !/usr/share/icons/papirus-antix/22x22/actions/search.png") rm /tmp/agenda_search_results.txt grep -i $event_to_search $HOME/yad-calendar.txt > /tmp/agenda_search_results-desorganized.txt grep -i $event_to_search $HOME/yad-calendar.txt > /tmp/agenda_search_results-desorganized.txt sort -t- -k3.1,3.4 -k2,2 /tmp/agenda_search_results-desorganized.txt > /tmp/agenda_search_results.txt #Display results yad --window-icon=$window_icon --title="antiX Calendar" --no-buttons --width=550 --height=550 --center --separator=" " --list --column="" < /tmp/agenda_search_results.txt pkill yad exit 1 } export -f Adicionar_evento Editar_evento search_event touch $calendar_file && [ -s $calendar_file ] || echo "28/06/2020 This is how yad-calendar entries work! Add ONLY ONE line per day, starting with the date. If nothing shows up in the calendar, try another date format like dd-mm-yyyy" > $calendar_file #Main window day=$(yad --window-icon=$window_icon --title="antiX Calendar" --calendar --undecorated --mouse --details=$calendar_file --button=" !/usr/share/icons/papirus-antix/22x22/actions/search.png":"bash -c search_event" --button="X":1) if [[ $foo -eq 1 ]]; then pkill yad exit 1 fi if [[ $foo -eq 2 ]]; then exit fi #Exit if no day was selected [ -z "$day" ] && exit #If a day was selected, check if it has any events (a line starting with a date) if grep -q $day $calendar_file; then Editar_evento else Adicionar_evento fiJanuary 16, 2021 at 11:03 pm #50001ModeratorBobC
::I have a sick mind and am dreaming of having an “Popup Alarm” checkbox and an “Alarm sound” field where you select a sound file to play if you want a sound file to play when it pops up. It could submit a cron job to do it, so it would take almost no resources.
But you would need to remove it from the crontab if it was cancelled and add it when new or moved. I wonder if a sound can be played from cron?
Yes, it’s quite a script already. I did test it here.
January 16, 2021 at 11:27 pm #50003MemberPPC
::@BobC – My tiny alarm script (that reads time of the alarm from the yad-calendar.txt file can be made to work with terminal input/yad window to select a one time only alarm (that was how I tested it).
The alarm script, being based in “sleep” runs in almost no RAM and CPU at all- less than it takes to run Cron.
That said, I do run cron on my work PC and thought about using it as an alarm, but it seems to take some time to update the cronjobs- you can set an alarm for 5 minutes in the future and it may not go off because cron didn’t update- at least that was what I read online… But, yes, you can create a cron job, for example, to run mpv playing a mp3 file, everyday at 08:00, and use it as an alarm clock- I read on script that did something like that…
Also- did you ever heard about the “rtcwake” command? https://linux.die.net/man/8/rtcwake
You can use it to suspend your pc and then wake it up at a certain time- and yes, use a script, in conjunction with that, to play an audio file/video at a certain time (Example, use rtcwake to wake your pc at 7:58, and, then have a cronjob or a sleep command have mpv play some sound…
I resorted to the “sleep” command because it never fails, does not require cron to be installed and it’s very light…The “antiX Calendar” main script tired the soul out of me, I was trying to fix all the possible quirks before I lose steam… The time validation part of the script is particularly nasty to make work… But has is, the script works perfectly – as long as you take care to write valid times (same thing as writing something in your paper agenda)
It now automatically organizes daily entries entries (that was bugging me).
Any user that uses the event’s “end time”, please be careful- I did not make the alarm script work with a time value that includes “end time” too (it’s an easy fix, but I’m dead tired, completely depleted…
Even so, I hope anti picks this up- I always imagined how cool it would be if we could use the yad-agenda, just one click away as a real PIM… Now I already do that- a yad window just came up, warning me it’s time to go to bed…I guess I’ll take tomorrow off…
P. -
AuthorPosts
- You must be logged in to reply to this topic.