Exporting ical Calendar Entries

‘No time. See you in Heaven.’
Interesting Times

I had a few problems with ical, erm, Apple’s Calendar app, last year. Entries that were not synched. And yeah, while I should not make any difference, given that there are entries that are 13 years old … that might make a difference. And it’s a liability. It get’s synced via Apple’s servers.

So, why not do a spring end of the year cleaning?

I actually went though the month view for each month in which I had entries, selected all (cmd + a) and deleted the entries. Which meant “having to contact” people who were participants in these appointments.

Well, yeah, fuck it. If that’s what has to happen to remove them — blame Apple. It shouldn’t matter when you do an Etch A Sketch on your calendar. But so be it.

But there is the issue of backups. I want to remove the entries from my calendar, but first of all, I want to secure them — locally and primarily for me. You can — easily — export a calendar. Just select it and select “File” > “Export” > “Export …”. Just save it as an .ics file.

But that’s not very readable. So here’s an R function (using the ical package) to turn it into something more … usable. Just … it’s without warranty, written today in a moment between conference calls:

writeIcalsToLogbook <- function(directoryFileICS = NULL) {
    if(is.null(directoryFileICS)) stop("Provide directory and ics file") 
    if (!require('ical')) install.packages('ical'); library('ical')
    icsTable <- ical_parse_df(text = readLines(directoryFileICS))
    icsTable <- icsTable %>% filter(!is.na(uid)) %>% select(-uid)
    icsTable <- icsTable %>% arrange(start)
    fileConn <- file(str_replace(directoryFileICS, ".ics", ".txt"))
    outputString <- ""
    for(i in 1:nrow(icsTable)) {
        outputString <- paste0(outputString, icsTable[[i, "start"]], " - ", icsTable[[i, "end"]], "\n", icsTable[[i, "summary"]], "\n", ifelse(!is.na(icsTable[[i, "description"]]), icsTable[[i, "description"]], ""), "\n\n\n")
    writeLines(outputString, fileConn)

Just provide it with the information where the .ics file is. It will generate a .txt file in the same directory.



will lead to a


file in that directory.

And it will show the dates (from — to) with the title and the additional information.

So you keep the data … just not online.