How can you programmatically import ics files?
My work used MS Exchange , and i like to export business meetings to ics files so that I can import them into Apple calendar to get reminder of them on my iPhone. Sometimes I get too busy and forget to check my personal mail in order to import the ics file. This has led to more than one missed meeting as I get pretty deep my work of writing code, architecting systems, etc. So much so, sometimes it takes coworker leaving for the day to remind me that I should go home for the day, too!
Since my Mac at home is always online, I've looked at using Dropbox/Hazel instead of email/applescript, but it looks like either way I hit the same stumbling block - programmatically ( i.e. non-interactively ) importing the ics file. I've found snippets of Applescript that may work with some tweaking. The below one runs until the Calendar app opens prompting for the name of the calendar to import the event into. I need to manually answer the prompt with cancel/ok at that point. I've changes the window title setting to "Add" and default calendar name setting to "Home", but it still gets stuck there.
set dupCalName to""
set thePath to (path to desktop as text) & "Personal.ics"
tell application id "com.apple.iCal"
activate
-- Get the application's name (presumably either "iCal" or "Calendar") for the GUI Scripting later. set iCalName toits name
-- Since it's possible for more than one calendar to have the same name, the repeat loop idea is better than simple name references here. But only one loop is necessary in this part of the script. repeatwith i from 1 to count of calendars
set thisCalendar to calendar i -- Gets an id reference to the calendar. if (name of thisCalendar is"Personal") then
set dupCalName to"Personal"
set replacementName to"Personal (old)"
set name of thisCalendar to replacementName
elseif (name of thisCalendar is"Personal 2") then
set dupCalName to"Personal 2"
set replacementName to"Personal 2 (old)"
set name of thisCalendar to replacementName
endif
endrepeat
endtell
delay 1
-- "Double-click" the file, since iCal/Calendar's 'open' doesn't work in later versions.tell application "Finder"to open file thePath
tell application "System Events"
tell process iCalName
-- Hedge bets over the name of the "Add Event" or "Add Events" window. tell (first window whose title beginswith"Add event")
repeat until (it exists)
delay 0.2
endrepeat
click pop up button 1
repeat until (menu 1 of pop up button 1 exists)
delay 0.2
endrepeat
click menu item "New Calendar"of menu 1 of pop up button 1
repeatwhile (menu 1 of pop up button 1 exists)
delay 0.2
endrepeat
click button "OK"
endtell
endtell
endtell
--check if a Personal 2 exists after the import of new iCal and change its nametell application id "com.apple.iCal"
activate
repeatwith i from 1 to count of calendars
set thisCalendar to calendar i
if (name of thisCalendar) is"Personal 2"then
set name of thisCalendar to"Personal"
exitrepeat
endif
endrepeat
endtell
tell application "SystemUIServer"
activate
if dupCalName isnot""then display dialog "Found an existing calendar named " & dupCalName & ". It has been renamed "& replacementName & "." buttons {"OK"} default button "OK"with icon 2
endtell
OS X El Capitan (10.11.2), 512GB SSD 16GB RAM