What is an "item" or convert a string to an item - Calendar Types in CalendarLib EC

CalendarLib EC is a script library for manipulating calendar events without using the Calendar application. Why? Its faster and probably more flexible.

This code snip shows a typical call to the library, note that the cal type is required and in this case is : cal cloud

set theStore to fetch store
set theCal to fetch calendar "Work" cal type cal cloud event store theStore

I have been attempting to pass the cal type in the form of a variable but the library throws an error “invalid cal type” and suggests that the type required is an item

set tCalType to CalendarType(pCalendarName, pCalTypesLst) -->
	-->tCalType is a string "cal type"
	set tSourceCal to fetch calendar pCalendarName cal type tCalType event store pTheStore

While I can hard code my call as per the first code snip I wonder if there is a way of coercing my variable into a form that is accepted by the fetch calendar handler. This handler is listed below and I have to admit that I do not understand the first code line → cal type calType, looking at the code here suggests that calType is a string but it is not as it gets displayed in blue in editor and a string throws an error.

-- You often need a reference to the relevant calendar; get it here.
on fetch calendar calName cal type calType event store theStore
	if calType = cal local then
		set calType to 0
	else if calType = cal cloud then
		set calType to 1
	else if calType = cal exchange then
		set calType to 2
	else if calType = cal subscription then
		set calType to 3
	else if calType = cal birthday then
		set calType to 4
	else
		error "Invalid cal type"
	end if
....

thanks in advance,
Simon

From the pdf guide I see that the list of types are enum :

cal types enum : Calendar types
cal local : Local.
cal cloud : iCloud/CalDAV.
cal exchange : Exchange.
cal subscription : Subscription.
cal birthday : Birthday.

Simon

Solving my own dumb question:

set tCalType to cal cloud
set tSourceCal to fetch calendar pCalendarName cal type tCalType event store pTheStore

So is an enum a little like a list of constants? I did try passing an integer but that failed which suggests an enum is a more complex type or class.

Simon

It’s not so much complex, as simply required – you can’t pass a string or any other class instead.

Around 2011 the scriptability of Calendar deteriorated. Somehow system safety improvements made it impossibly slow to script Calendar or it just failed. That’s when the predecessor of this library was created and it has been incredibly useful .

Yes. You can generally see them when viewing a dictionary with Script Debugger.