iCal calendar enumeration with "whose name does not contain"

Hello,

I would like to work with the events of a subset of my calendars.

set calendars_to_ignore to {"foo", "bar"}

tell application "iCal"
	set calendars_list to name of every calendar as list whose name is not in calendars_to_ignore
	repeat with current_calendar in calendars_list
		-- ... do something ...
	end repeat
end tell

I’ve also tried

...
	set calendars_list to name of every calendar as list
	repeat with current_calendar in (calendars_list whose name is not in content of calendars_to_ignore)
...

and variations of that.

But both times I get an error like “error “ž{"foo", "bar"} whose not 64” could not be read.” number -1728

I guess I’m mixing lists with records, but obviously I haven’t understood any one of them properly…
Can anybody please point me in the right direction?

try this…

set calendars_to_ignore to {"foo", "bar"}

tell application "iCal"
	set calendars_list to name of every calendar
	repeat with current_calendar in calendars_list
		if current_calendar is not in calendars_to_ignore then
			-- do something
		end if
	end repeat
end tell

:rolleyes:
maelcum slaps his forehead

Oh my… Thanks Hank/regulus6633. Sometimes I am standing right beside me… I was so obsessed to do with a “whose”-clause…
Sorry and again: Thank you!

Nah, that didn’t work out when it’s added to the grand scheme of things… :expressionless:
After inserting the if-clause, the rest of the script barfs. And I am totally puzzled as to why…
It looks as if the calendars, once referenced by name, are now only available as ids…

set calendars_to_ignore to {"foo", "bar"}
set current_date to current date


tell application "iCal"
	--  Search through all calendars, one by one
	repeat with current_calendar in calendars
		--  alternative way to write would be:
		--set calendars_list to name of every calendar
		--repeat with current_calendar in calendars_list
		
		--if current_calendar is not in calendars_to_ignore then
		
		--  Wade through all events in each calendar that occur in the defined time frame
		repeat with current_event in ((every event of current_calendar) whose ((start date ≥ current_date)))
			
			-- do something
		end repeat
		--end if
	end repeat
end tell

try this…

set calendars_to_ignore to {"foo", "bar"}

tell application "iCal"
	set calendars_list to every calendar
	repeat with current_calendar in calendars_list
		if (name of current_calendar) is not in calendars_to_ignore then
			-- do something with the calendar
			-- now current_calendar is the actual calendar rather than just the name
		end if
	end repeat
end tell

Note:


repeat with current_event in ((every event of current_calendar) whose ((start date ≥ current_date)))
			
	-- do something
end repeat

will be very slow because the filtered list will be retrieved every iteration of the loop.
This is better:

set theEvents to (every event of current_calendar whose start date ≥ current_date)
repeat with current_event in theEvents		
	-- do something
end repeat

THANK YOU regulus6633 (it works! :lol: ) and StefanK (it makes everything quicker by a factor of 5 = 500% :D).

As a newbie to AS-scripting I follow the orders given http://macscripter.net/guidelines.php and “proffer my script” (read: me reinventing the wheel). And it’s not even my script, I’d say. Just copied and pasted.

Since updating this post with new versions always bumps it up to the beginning of the list, the final solution has been moved here: http://macscripter.net/viewtopic.php?id=31862

I hope this is the last bump. Thanks again for all who have helped.