2

I use org-icalendar-export-to-ics to export org-agenda scheduled tasks to iCal format, which works nicely. In my use case, I always select export the "current file" (as opposed to "combine all agenda files").

This has the effect of creating an .ics file with a name like foo.ics. I then have to go navigate in Finder to go find that file and then open it in iCal.

How can I direct Emacs to open or open-with that .ics file automatically upon org-icalendar-export-to-ics? I can't imagine a scenario where I would want to export to an .ics file but not go on to open the .ics file and import the task into iCal.

Maybe some bash scripting around org-after-save-iCalendar-file-hook? The documentation for org-after-save-iCalendar-file-hook says "A good way to use this is to tell a desktop calendar application to re-read the iCalendar file," but it doesn't say how to go about telling my desktop calendar to do that.

incandescentman
  • 4,111
  • 16
  • 53
  • 1
    How about? `(defun test-fn (file) (start-process "my-process" nil "open" "-a" "/Applications/iCal.app" file)) (add-hook 'org-after-save-iCalendar-file-hook 'test-fn)` – lawlist Nov 16 '16 at 17:37
  • @lawlist Thanks! Doesn't work yet. Do we need to specify the file in the hook somehow? – incandescentman Nov 16 '16 at 18:29
  • 1
    Can we please clarify the name of the hook -- the hook specified in your question is different than the one I see here: http://orgmode.org/w/?p=org-mode.git;a=blob_plain;f=lisp/ox-icalendar.el;hb=HEAD In the code that I linked to, the hook is named `org-icalendar-after-save-hook`. Once we get the name of the hook correct, you can start with a simple test to just generate a message in the `*Messages*` buffer: `(defun test-fn (file) (message "This is the name of the file: %s" file)) (add-hook 'org-icalendar-after-save-hook 'test-fn)` Then, adjust the name of the hook in the first comment. – lawlist Nov 16 '16 at 18:38
  • @lawlist You were right, that was the problem. I modified a couple other things, this code now works: `(defun org-icalendar-open-ics-file (file) (start-process "org-icalendar-open-ics-file-process" nil "open" "-a" "/Applications/Calendar.app" file)) (add-hook 'org-icalendar-after-save-hook 'org-icalendar-open-ics-file)` – incandescentman Nov 16 '16 at 18:46
  • 1
    Yes, newer versions of OSX have renamed `iCal` to `Calendar` -- I'm glad we got it all sorted out. – lawlist Nov 16 '16 at 18:47

1 Answers1

3

In conjunction with the assistance of the original poster in the comments above, here is the final solution:

(defun org-icalendar-open-ics-file (file)
  (start-process "org-icalendar-open-ics-file-process" nil "open" "-a" "/Applications/Calendar.app" file))

(add-hook 'org-icalendar-after-save-hook 'org-icalendar-open-ics-file) 
lawlist
  • 18,826
  • 5
  • 37
  • 118
  • When I use org-icalendar-combine-agenda-files, the created ics should open correct? it is not working on my end. Nothing happens. Just the ics gets created. – Adelita Feb 15 '23 at 22:08
  • 1
    @Adelita -- I don't have access to a modern version of MacOS .. the newest I have is El Capitan on one laptop. This question/answer is from the year 2016 ... things may have changed on newer versions of the OS and the aspect of org-mode that is related to this issue may also have been updated since then. – lawlist Feb 16 '23 at 00:31
  • Fair point. thanks for your asnwer. – Adelita Feb 16 '23 at 06:09