{ "id": "https://www.tunbury.org/2020/02/06/import-text-file-of-events-into-apple-calendar-using-applescript", "title": "Import Text File of events into Apple Calendar using AppleScript", "link": "https://www.tunbury.org/2020/02/06/import-text-file-of-events-into-apple-calendar-using-applescript/", "updated": "2020-02-06T12:41:29", "published": "2020-02-06T12:41:29", "summary": "The Church of England has a very useful calendar page, but I’d really like it in my iPhone calendar so I can have reminders for Saints’ days particularly red letter days when the flag goes up.", "content": "

The Church of England has a very useful calendar page, but I’d really like it in my iPhone calendar so I can have reminders for Saints’ days particularly red letter days when the flag goes up.

\n\n

I’ve never used AppleScript before but with a little searching online it seemed relatively easy to create a script to import a text file copy of the web page into my Mac calendar which is synchronised with my phone.

\n\n
set OldDelimiters to AppleScript's text item delimiters\nset LF to ASCII character 10\nset tab to ASCII character 9\nset theFile to choose file with prompt \"Select TAB delimited file calendar file\"\nset theLines to read theFile\nset AppleScript's text item delimiters to {LF}\nset theLines to paragraphs of theLines\nset AppleScript's text item delimiters to {tab}\nrepeat with ThisLine in theLines\nif (count of ThisLine) > 0 then\nset theStartDate to current date\nset hours of theStartDate to 0\nset minutes of theStartDate to 0\nset seconds of theStartDate to 0\n\nif text item 1 of ThisLine is not \"0\" then\nset year of theStartDate to text item 1 of ThisLine as number\nend if\n\nif text item 2 of ThisLine is equal to \"January\" then\nset month of theStartDate to 1\nelse if text item 2 of ThisLine is equal to \"February\" then\nset month of theStartDate to 2\nelse if text item 2 of ThisLine is equal to \"March\" then\nset month of theStartDate to 3\nelse if text item 2 of ThisLine is equal to \"April\" then\nset month of theStartDate to 4\nelse if text item 2 of ThisLine is equal to \"May\" then\nset month of theStartDate to 5\nelse if text item 2 of ThisLine is equal to \"June\" then\nset month of theStartDate to 6\nelse if text item 2 of ThisLine is equal to \"July\" then\nset month of theStartDate to 7\nelse if text item 2 of ThisLine is equal to \"August\" then\nset month of theStartDate to 8\nelse if text item 2 of ThisLine is equal to \"September\" then\nset month of theStartDate to 9\nelse if text item 2 of ThisLine is equal to \"October\" then\nset month of theStartDate to 10\nelse if text item 2 of ThisLine is equal to \"November\" then\nset month of theStartDate to 11\nelse if text item 2 of ThisLine is equal to \"December\" then\nset month of theStartDate to 12\nelse\nlog text item 2 of ThisLine\nend if\n\nset day of theStartDate to text item 3 of ThisLine\n\nset theEndDate to theStartDate + (23 * hours)\n\nlog theStartDate\n\ntell application \"Calendar\"\nif text item 5 of ThisLine is \"RED\" then\ntell calendar \"CofE RED\"\nif text item 1 of ThisLine is not \"0\" then\nset newEvent to make new event with properties {summary:text item 4 of ThisLine, start date:theStartDate, end date:theEndDate, allday event:true}\nelse\nset newEvent to make new event with properties {summary:text item 4 of ThisLine, start date:theStartDate, end date:theEndDate, allday event:true, recurrence:\"freq=Yearly\"}\nend if\nend tell\nelse\ntell calendar \"CofE\"\nif text item 1 of ThisLine is not \"0\" then\nset newEvent to make new event with properties {summary:text item 4 of ThisLine, start date:theStartDate, end date:theEndDate, allday event:true}\nelse\nset newEvent to make new event with properties {summary:text item 4 of ThisLine, start date:theStartDate, end date:theEndDate, allday event:true, recurrence:\"freq=Yearly\"}\nend if\nend tell\nend if\nend tell\n\nend if\n\nend repeat\n \nset AppleScript's text item delimiters to OldDelimiters\n
\n\n

cofe-calendar

", "content_type": "html", "author": { "name": "Mark Elvers", "email": "mark.elvers@tunbury.org", "uri": null }, "categories": [ "applescript" ], "source": "https://www.tunbury.org/atom.xml" }