The last business day of every month excluding my country's holidays

I have a Calendar called “My Company” where I need to create an evert the business day before the last business day.

Example: February 2021 ends on a sunday. The last business day of february is 26, friday. I need to set an event febuary 25.

Another example: May 2021 ends on a monday. The business day before that is friday 28. But suppose that was a holiday. Then the business day before the last business day of may would be thursday 27.

The calendar I am trying to check against is this one

http://icalshare.com/calendars/3372

that I call inside Calendar “Feriados Portugal”.

This is my script so far.

set numberOfDaysPerMonth to {}
set templateDates to {}
set i to 1
repeat while i < 13
	copy (current date) to newDate
	set currentYear to year of newDate
	set the month of newDate to (i as integer)
	set the day of newDate to (1 as integer)
	
	set numberOfDaysOnMonth to GetNumberOfDaysInMonth(newDate)
	copy numberOfDaysOnMonth to end of numberOfDaysPerMonth
	
	--	copy {i:newDate} to end of templateDates
	
	set i to i + 1
end repeat


my GetNumberOfDaysInMonth(newDate)


# Returns the number of days in the month that the given date falls in.
# Example:
#     my GetNumberOfDaysInMonth(current date)
on GetNumberOfDaysInMonth(aDate)
	local aDateCopy
	copy aDate to aDateCopy
	set day of aDateCopy to 1
	if month of aDateCopy is December then
		set year of aDateCopy to ((year of aDateCopy) + 1)
		set month of aDateCopy to 1
	else
		set month of aDateCopy to ((month of aDateCopy) + 1)
	end if
	return day of (aDateCopy - 1 * days)
end GetNumberOfDaysInMonth

this script discovers the last day of each month and stores it at numberOfDaysPerMonth

Now I am trying to get all events from calendar “Feriados Portugal” using this code:

tell application "Calendar"
	tell calendar "Feriados Portugal"
		set eventos to every event
		display dialog start date of first event of eventos
	end tell
end tell

this is what I get just for the first event!:https://ibb.co/SxwjF0s

What I need is simply a list of dates.

Hi macos_boy.

Your ‘eventos’ variable contains an AppleScript list containing specifiers for all the events returned by ‘every event’. So you want the start date of item 1 of eventos. Alternatively, you could get the start date of event 1 of the calendar, but that would be slower if you did it for every event.

You’ll need to coerce the date to text if you want to display it in a dialog.

tell application "Calendar"
	tell calendar "Feriados Portugal"
		set eventos to every event
		display dialog ((start date of first item of eventos) as text)
	end tell
end tell

Or:

tell application "Calendar"
	tell calendar "Feriados Portugal"
		display dialog ((start date of event 1) as text)
	end tell
end tell

Or more likely, if you’re just after a list of start dates:

tell application "Calendar"
	tell calendar "Feriados Portugal"
		set startDates to start date of every event
		display dialog ((item 1 of startDates) as text)
	end tell
end tell

SIMPLY BRILLIANT!!!
thanks!