Hello,
I wonder if anyone can help with AppleScript and knows the latest OSX Calendar functions well.
My goal is to backup each calendar within the Calendar application to a single directory as .ics files.
I've been reading through this post from 2007 and tried to modify the script from xUKHCx without any success. I assume that the Calendar application has changed quite a bit over the last 5 years.
The end result should be as in the attached screenshot. Any help is greatly appreciated - after 2 days of searching through Google and other forums.. I'm out of skills and ideas!
I wonder if anyone can help with AppleScript and knows the latest OSX Calendar functions well.
My goal is to backup each calendar within the Calendar application to a single directory as .ics files.
I've been reading through this post from 2007 and tried to modify the script from xUKHCx without any success. I assume that the Calendar application has changed quite a bit over the last 5 years.
Code:
-- Set paths and variables ------------------------------------------------------------------------------------
set timeStamp to do shell script "date \"+%Y%m%d\""
set calendar_folder to POSIX path of (path to home folder from user domain)
set sources_folder to quoted form of (calendar_folder & "Library/Calendars")
set backup_folder to POSIX path of ("Users/ros/Backup/Calendar/")
-- Find all Info.plist files ---------------------------------------------------------------------------------
set infolist to paragraphs of (do shell script "find -f " & sources_folder & "| grep -v /Contents | grep Info.plist$")
set calstartlist to {}
set caldestlist to {}
set calnamelist to {}
-- Create a backup folder -------------------------------------------------------------------------------------
try
set destfolder to backup_folder
set fileName to timeStamp
do shell script "mkdir -p " & quoted form of destfolder & "/" & quoted form of fileName
set destFile to destDir & "/" & fileName
end try
-- Search through above results -------------------------------------------------------------------------------
repeat with calname in infolist
set calname to calname as string
set calname to text 1 thru -7 of calname
-- Create a path to the original .ics files -------------------------------------------------------------------
set calstart to quoted form of (text 1 thru -5 of calname & "corestorage.ics")
copy calname to end of calstartlist
set calname to quoted form of calname
-- Read the Info.plist and grab the calendar names ------------------------------------------------------------
try
set calname to (do shell script "defaults read " & calname & " Title")
set caldest to quoted form of (backup_folder & calname & ".ics")
copy calname to end of calnamelist
copy caldest to end of caldestlist
end try
end repeat
set calexport to choose from list calnamelist with multiple selections allowed
repeat with calname in infolist
set calname to calname as string
set calname to text 1 thru -7 of calname
set calstart to quoted form of (text 1 thru -5 of calname & "corestorage.ics")
copy calname to end of calstartlist
set calname to quoted form of calname
try
set calname to (do shell script "defaults read " & calname & " Title")
set caldest to quoted form of (backup_folder & calname & ".ics")
if calname is in calexport then
do shell script "ditto " & calstart & " " & caldest
end if
end try
end repeat
The end result should be as in the attached screenshot. Any help is greatly appreciated - after 2 days of searching through Google and other forums.. I'm out of skills and ideas!