# how to automatically open .ics file after org-icalendar-export-to-ics?

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.

• 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
• Can we please clarify the name of the hook -- the hook specified in your question is different than the one I see here: orgmode.org/w/?p=org-mode.git;a=blob_plain;f=lisp/… 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
• 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 Answer

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)