Export Calendar data to archive (icbu) file

Hello,

I’m trying

tell application “Calendar”
save document 1 in alias(“myuserpath:test.icbu”) as archive
end tell

but this doesn’t compile (error 2741: Expected class name but found identifier.)

Suppressing «as archive» fixes the compilation problem, then the script runs without an error message, but no file is created.

Anyone knows how to use the save (as archive) command?

Thanks

There is no AppleScript command to archive the calendars.

A workaround is to GUI script the Export > Calendar Archive… menu item in the File menu.

Edit:

This is a GUI script to archive the data, you have to replace /Users/myself/ with the real (POSIX path) and test (without extension) if the file name is different. The repeat loops in the script wait for appearing/disappearing of the sheets

activate application "Calendar"
tell application "System Events"
	tell process "Calendar"
		click menu item "Calendar Archive…" of menu 1 of menu item "Export" of menu 1 of menu bar item "File" of menu bar 1
		repeat until exists sheet 1 of window 1
			delay 0.2
		end repeat
		tell sheet 1 of window 1
			keystroke "g" using {command down, shift down}
			repeat until exists sheet 1
				delay 0.2
			end repeat
			tell sheet 1
				set value of text field 1 to "/Users/myself/"
				keystroke return
				repeat while exists sheet 1
					delay 0.2
				end repeat
			end tell
			set value of text field 1 to "test"
			click button "Save"
		end tell
	end tell
end tell