Skip to content

Instantly share code, notes, and snippets.

@jetztgradnet
Created June 30, 2015 23:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jetztgradnet/bee231bb4d0965ef055c to your computer and use it in GitHub Desktop.
Save jetztgradnet/bee231bb4d0965ef055c to your computer and use it in GitHub Desktop.

Script to extract iCloud calendar URLs

This script can be used to extract iCloud calendar URLs. As a prerequisite the calendars must be visible in your local Calendar.app or iCloud preference pane.

The calendar configuration is stored in ~/Library/Calendars with sub folders for individual calendars.

Example output:

> icloud-calendars
/Users/myuser/Library/Calendars/XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB.caldav/Info.plist
calendar base url: https://p05-caldav.icloud.com/1234567890/principal/
Calendar: /1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-222222222222/
 url https://p05-caldav.icloud.com/1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-222222222222/
 (defined in /Users/myuser/Library/Calendars/XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB.caldav/DDDDDDDD-EEEE-1234-AAAA-222222222222.calendar/Info.plist)
Family: /1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-333333333333/
 url https://p05-caldav.icloud.com/1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-333333333333/
 (defined in /Users/myuser/Library/Calendars/XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB.caldav/DDDDDDDD-EEEE-1234-AAAA-333333333333.calendar/Info.plist)
Private: /1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-444444444444/
 url https://p05-caldav.icloud.com/1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-444444444444/
 (defined in /Users/myuser/Library/Calendars/XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB.caldav/DDDDDDDD-EEEE-1234-AAAA-444444444444.calendar/Info.plist)
☞Library Loans: /1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-555555555555/
 url https://p05-caldav.icloud.com/1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-555555555555/
 (defined in /Users/myuser/Library/Calendars/XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB.caldav/DDDDDDDD-EEEE-1234-AAAA-555555555555.calendar/Info.plist)
Office: /1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-666666666666/
 url https://p05-caldav.icloud.com/1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-666666666666/
 (defined in /Users/myuser/Library/Calendars/XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB.caldav/DDDDDDDD-EEEE-1234-AAAA-666666666666.calendar/Info.plist)
Reminders: /1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-777777777777/
 url https://p05-caldav.icloud.com/1234567890/calendars/DDDDDDDD-EEEE-1234-FFFF-777777777777/
 (defined in /Users/myuser/Library/Calendars/XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB.caldav/DDDDDDDD-EEEE-1234-AAAA-777777777777.calendar/Info.plist)

Installation

Store the file in ~/bin/icloud-calendars and make it executable using chmod +x icloud-calendars. Then it can simply be run as icloud-calendars or ~/bin/icloud-calendars if ~/bin is not on the $PATH.

#!/bin/bash
############################################################################
#
# This script lists the URLs for all locally visible iCloud calendars. These
# URLs can be used to e.g. register the calendars in other calendars such
# as Lightning (Thunderbird plugin) or Outlook.
#
# (c) 2015 Wolfgang Schell
#
############################################################################
# root directory for calendars
ROOT=~/Library/Calendars
# find base directory of icloud calendars
for calfile in $(grep -R -I -l -s caldav.icloud.com $ROOT/*); do
echo "$calfile"
calurl=$(/usr/libexec/PlistBuddy -c "Print PrincipalURL" "$calfile" 2>/dev/null )
echo "calendar base url: $calurl"
calbaseurl=$(echo "$calurl" | awk -F/ '{print $3}')
caldir=$(dirname "$calfile")
# find sub directory of individual icloud calendars
for subcalfile in $(find "$caldir" -name Info.plist -print); do
calpath=$(/usr/libexec/PlistBuddy -c "Print CalendarPath" "$subcalfile" 2>/dev/null)
calname=$(/usr/libexec/PlistBuddy -c "Print Title" "$subcalfile" 2>/dev/null)
if [ -n "$calname" -a -n "$calpath" ]; then
echo "$calname: $calpath"
echo " url https://$calbaseurl$calpath"
echo " (defined in $subcalfile)"
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment