Read the statement by Michael Teeuw here.
Synchronizing private iCloud calendar with MagicMirror - a Workaround
-
I found a solution how to automatically sync a private iCloud calendar to the magic mirror. It’s quite circuitous. And it’s more like a workaround, not a real solution.
But since you can’t access a private iCloud calendar directly via any API or something similar, this is the only working solution I found.
Maybe it’s helpful for one of you.Why?
I don’t want my calendar to be available via a public URL like mentioned in the iCloud calendar thread. Even though the public sharing address is quite long, web crawlers can still find them and your private life is publicly available. I just don’t like that scenario. So I wanted a solution that uses encryption and authentication against all services.
I’m using a shared calendar with my girlfriend via iCloud. I’d use my CalDAV server Baïkal for that, but the current version of the backend (sabre/dav) in Baïkal does not yet support calendar sharing (they’re working on it). So until then, we’re quite stuck with iCloud since all the other CalDAV servers I tried don’t satisfy me and I have good experiences with Baïkal.
Preconditions
You’ll need:
- Computer running macOS
- iCloud calendar synced in
Calendar.app
- iCloud calendar synced in
vdirsyncer
- A CalDAV server (I use Baïkal)
- MagicMirror (of course)
How it works
The
Calendar.app
saves an.ics
file for every calendar event to the hard drive. We can use these event files to use withvdirsyncer
and synchronize them with a CalDAV server. So the sync chain would be like the following:iCloud < - > Calendar.app -> Filesystem -> CalDAV Server -> MagicMirror
Steps
Find the directory of the desired calendar
macOS’ Calendar.app saves it’s calendar files in
/Users/[USER]/Library/Calendars/
.
In this Folder you’ll find several folders with suffixes like.caldav
and.calendar
depending on your configuration. The folders should be identified by UUIDs. iCloud accounts should have a.caldav
suffix.Every folder contains a
Info.plist
file on which you can identify the calendar of the CalDAV account. You just have to look for the one containing your iCloud ID.In this folder you can find subfolders with
.calendar
suffixes. These subfolders also contain anInfo.plist
file that should have information to identify the desired calendar.In the calendar folder is a
Events
folder that contains all the.ics
files with your calendar events. This is the folder we’re looking for.CalDAV server
I won’t explain how to install and set up a CalDAV server, you can use the one of your choice. I have good experiences with Baïkal, but other implementations like DaviCAL or radicale should work as well. You can read more about Baïkal on baikal-server.com oder Baïkals GitHub repo.
I created an extra user for the mirror. We’ll use
magicmirror
for the rest of the tutorial.Install and configure
vdirsyncer
You can install
vdirsyncer
via Homebrew on macOS:brew install vdirsyncer
You might want to start
vdirsyncer
on system startup so it syncs events automatically:brew services start vdirsyncer
Here’s a sample configuration to sync with the CalDAV server:
# An example configuration for vdirsyncer. # # Move it to ~/.vdirsyncer/config or ~/.config/vdirsyncer/config and edit it. # Run `vdirsyncer --help` for CLI usage. # # Optional parameters are commented out. # This file doesn't document all available parameters, see # http://vdirsyncer.pimutils.org/ for the rest of them. [general] # A folder where vdirsyncer can store some metadata about each pair. status_path = "~/.vdirsyncer/status/" # Synchronize all collections that can be found. # You need to run `vdirsyncer discover` if new calendars/addressbooks are added # on the server. # CALDAV [pair MyPairing] a = "Local" b = "Remote" collections = null # Calendars also have a color property metadata = ["displayname", "color"] # The storage name must be "Events", because it looks for it in the .calendar folder [storage Local] type = "filesystem" # This folder should not go to the Events folder but to the parent directory path = "/Users/YOURUSER/Library/Calendars/0b0e91ad-60d1-40e2-85cf-366b2ddb5f1b.caldav/63cf04c6-d391-41af-840c-4e4a4d2ed37b.calendar/Events/" fileext = ".ics" # This might be important, since you don't want vdirsyncer to change anything in the Calendar.app folder: read_only = true [storage Remote] type = "caldav" # "magicmirror" is the username! url = "https://baikal.example.org/dav.php/calendars/magicmirror/MYCALENDAR/" auth = "digest" username = "magicmirror" password = "YOURSTRONGPASSWORD"
For further information about the config, please refer to the
vdirsyncer
documentation.You can discover the new files with the following command:
vdirsyncer discover
… and trigger a sync with this command:
vdirsyncer sync
When it’s successfully configured and running,
vdirsyncer
automatically synchronizes the content of theEvents
folder with the CalDAV server periodically.Use the default calendar module with the CalDAV server
Just add your credentials to the MagicMirror configuration. If you want to use digest authentication (with Baïkal for example), you have to change the
sendImmediately
option in thecalenderfetcher.js
tofalse
. You can find it here.If you use Baïkal or any other service that uses sabre/dav (like Nextcloud), you have to add the
?export
option to the calendar URL as described in the CalDAV thread.Here’s an example URL for use with Baïkal:
https://dav.example.org/dav.php/calendars/[username]/Events?export
This URL returns an
.ics
file with the whole calendar containing all the events.I hope someone has use for this ;)
- Computer running macOS
-
@Beh Thank you for this, wizard! I made my calendar public and also do not like that option, really. What I can see using my calendar is just the title and time until event will happen. What I’d also like to see is the ‘description’ I add to my events, for example “Work” as title and “07.00-16.00” as description. Would this be possible using this method? Before I venture on to try this I would like to see a picture on how this looks. Any chance of a visual? Thanks again.
-
@Advokaten
The data will be transferred, sincevdirsyncer
synchronizes the whole calendar data (including description, location, time, title,…). So all the calendar data you enter in your iCloud account will be synchronized to your mirror.What you are asking depends heavily on the calendar module you are using on your mirror. I don’t think, that the default module supports this. So I think one needs to change stuff in the calendar module for this to work.
So I think what you’re asking is not really related to the syncing itself. If you’re already using the default calendar module, you already know how it looks. I didn’t change a single thing on that regarding optics. So the look is 100% similar to the default calendar module.
-
To all future readers:
I found a way better solution for this. You can check it out in this thread:
https://forum.magicmirror.builders/topic/5327/sync-private-icloud-calendar-with-magicmirror
/cc @Advokaten