Toggle Google Calendar Show/Hide in Apple Calendar

Does anyone know how to make it so I can toggle a calendar that shows up in Apple Calendar from a Google calendar I sync to it? Not sure if the Google calendar makes a difference or not. Here is an example of what I have so far that is not working.

tell application "Calendar"
    set calendarList to calendars
     for calendar in calendarList
        if calendar's name = "Work Appointments" then
            set visibility of calendar to not (calendar is visible)
            end if
    end for
end tell

I am running a decrepit version of ‘calendar’ so I have no clue what anyone else might be able to do.

You can find out the properties that you can set by picking a calendar and then getting its properties, like so:

properties of calendar "Automator"

or

properties of calendar 1

You might get results that look like this which would suggest that visibility is not available to set:

{class:calendar, description:"", uid:"B33041D7-D7C6-4508-A855-443B325BA24A", ¬
 title:"Automator", writable:true, color:{48962, 22233, 55928}}

These properties are also listed in the application’s dictionary (File > Open Dictionary…).

Yes that is what I got too so it seems that this is not possible. It stinks that they don’t add that to the view options and then I could just use Keyboard Maestro to select menu items.

I guess this is why third-party developers make calendar apps.

It should be possible to uncheck a given calendar which should make its entries vanish from the main view. It would require (I think) UI scripting. Dunno how smoothly that would integrate with KM.

Thanks, yeah, I have attempted, I think, with UI Browser in the past. Sadly, it is no longer supported. Fantastical is the only one that I know of that allows shortcuts for groups, but it has other downsides besides the ever-increasing subscription model. I found about a decade ago a Google Chrome plug-in allowed for this, but I don’t really want to be in a browser. I have thought about using Keyboard Maestro to do image recognition, but with about six calendars to turn on and off, that is a bit clunky. Thank you for all your help.

–Toggle On Calendar “Automator”

tell application “System Events”

tell application process “Calendar”

set t to checkbox 1 of UI element 1 of row 3 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window 1

set v to value of t

if v = 0 then

click t

end if

end tell

end tell