Make NewCalendar or Create NewCalendar. OSX 10.12.6 Sierra

While I read in the Calendar dictionary that “Create calendar” command is

I noticed the following:

  • Calendars created in AS with the “Make calendar” does not get deleted from the “Calendar” folder and the “Calendar cache” file, when you delete them from inside the Calendar.app. Clearly they have something wrong.

  • This does not happen with the “Create calendar” command

  • The first “Create calendar” runs fine. The second one hang the AS while the Calendar.App returns:

  • No error returned by AS.

  • The second created calendar does not get saved in the cache, does not create a folder in the library/calendar folder, but it appears on the Calendar.app.

  • ANY FOLLOWING Calendar creation runs just fine. ONLY the second one aborts.

This is the test script:

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Calendar"
	set TheCalendarName to "NewCal2"
	--activate
	try
		create calendar with name TheCalendarName
	on error tErr
		return tErr
	end try
end tell

So…it is a mess.
Should I just wait for when Apple will update Calendar Applescripting or is there something that I don’t understand?

Thanks

New finding:

If you “Create” the first calendar starting with the Calendar.app closed, any subsequent calendar creation runs fine…

Boh!

So…this always works (sigh)

if application "Calendar" is running then
	tell application "Calendar"
		close window 1
	end tell
end if

repeat with U from 1 to 3
	tell application "Calendar"
		set TheCalendarName to "NewCal" & U
		try
			create calendar with name TheCalendarName
		on error tErr
			return tErr
		end try
	end tell
end repeat