Rodrigo Amestica <ramest...@lavabit.com> wrote: > Hi, > > I use appt to connect desktop notifications to appointments in my > agenda. However, the connection between the appointments and the > notification system does not happen until I visit the agenda with, for > example, "C-c a a", which I sometimes forget to invoke and I end up > missing appointments. > > Trying to automate I created a short cut like this: > > emacs -f org-agenda-list my-main-org-file > > However, this seems to execute org-agenda-list before my-main-org-file > has fully opened in its own buffer and I end up with the window split into > two buffers: top one scratch and bottom one my-main-org-file, which is > visually very annoying. It is completely mysterious to me the timing > at which different actions take place within emacs and how to control > and sequence them, like a 'wait' call. > > Is there a way to automatically execute org-agenda-list after > my-main-org-file has fully finished opening in its buffer? >
I think this is the wrong way to go about it. > Is it there some more streamlined way to connect agenda to > notifications such that I would not need to explicitly enable them > every time I open the file? > The way to do it is to call org-agenda-to-appt. The trick is to call this function at all the necessary places/times. I have the following code in my initialization file, after the rest of org initialization: --8<---------------cut here---------------start------------->8--- ... (org-agenda-to-appt) (defadvice org-agenda-redo (after org-agenda-redo-add-appts) "Pressing `r' on the agenda will also add appointments." (progn (setq appt-time-msg-list nil) (org-agenda-to-appt))) (ad-activate 'org-agenda-redo) (add-hook 'org-capture-after-finalize-hook (function org-agenda-to-appt) ) ;; wrong (setq org-appt-timer (run-at-time "00:01" nil (function org-agenda-to-appt))) ... --8<---------------cut here---------------end--------------->8--- There are four pieces here: o an explicit call - this gets executed at initialization and loads up the appt-time-msg-list from the agenda. o advising org-agenda-redo so that after it's done, it resets appt-time-msg-list and calls org-agenda-to-appt again. That way, if something goes wrong, I can pop up the agenda, press "r" and start afresh. o add a call to org-capture-after-finalize-hook - that way when I capture an appointment for today, it will be added automatically. o finally, I would like to add a call at midnight every day to recalculate appointments for the next day - unfortunately, the call above is not correct, so for now I do it manually with an org-agenda-redo as above. One of these days I'll get that fixed. If anybody has done that already, I'll gladly steal your code :-) I *think* that should catch everything. BTW, there is an org-hacks entry by Russell Adams: http://orgmode.org/worg/org-hacks.html#org-agenda-appt-zenity where he suggests also adding it to org-agenda-finalize-hook: that way it gets done every time you display the agenda as well. Not sure whether it's necessary or overkill for me, but it certainly wouldn't hurt. Nick