Edit Subscription Cal or Duplicate to Second Cal with Edits

Issue:
I have two calendars to which I subscribe from an external source which handles officiating schedules for myself and my son. Both calendars are nearly identical as we often share scheduled times for these events.

The calendar places the exact same 50char title for each event of which we can see 15-20 chars prior to being truncated, and not a single word in the title is helpful beyond knowing what they’re denoting.

Request for Help:
I would be happy with either option of editing the live events of the subscribed cal or duplicating all the events into a second cal and hiding the first. I assume editing the subscribed cal could cause some conflicts or some other grief, so if it’s easier or just plain smarter to grab the events from one cal and paste into another, I imagine that could be handled by pulling the plain text from the .ics and replacing the text in the .ics file for the duplicated cal but with some dynamic changes to the event titles if possible. I could then just hide the original cals and show the duplicated content cals.

Timing:
This does not have to be constantly live updated, and could be fired off nightly at midnight with a script or cron job, or even manually if I make a copy of the script into an app and just run it after I know that I should have new events added to the cals. I would likely tell the Calendar app to quit and delay a few seconds to settle any related .ics/.plist file updates, and then run the script. I think it would be smarter to run two separate scripts, one for each cal for each person, rather than trying to combine them into a single thread of actions.

If possible, when the scheduled script runs, I could set a variable (our initials for the title var) for each person just before running the embedded script so that the same script gets used, just twice, and with variables set in the parent script. I’m not sure this is even doable. I know I can run a script from within a script, just not sure if I can pass variables to the child script. The same variable could be used for both the title edits as well as the name of the ics file being edited or replaced. A bonus would be that the original destination .ics file gets backed up with a timestamp in the filename in an adjacent folder or some other placed automatically updated by TimeMachine and BackBlaze.

Ideal Event Edit Scenario:
The events have the [50char] “title” replaced with some event details like: "JB Ref “[varEVENTDATE(%I:%M)]” @ "[varLOCATION()]

~ where the varLOCATION could be matched and swapped against a list of variable replacements like:

  1. Company XYZ Full Name East Rink at Road Blvd becomes XYZ - East[/*]
  2. Company XYZ Full Name West Rink at Road Blvd becomes XYZ - West[/*]
  3. Company QRS Full Name Rink One Black becomes QRS - Black[/*]
  4. Company QRS Full Name Rink Two Red becomes QRS - Red[/*]
  5. Company QRS Full Name Rink Three Blue becomes QRS - Blue[/*]
  6. …List consists of 15-20 items against which the script would check and change text[/*]

Preferred Event Edit Scenario:
The events have the [50char] “title” replaced with some event details like: "JB Ref "[varEVENTDATE(%I:%M)]

Base Event Edit Scenario:
The events have the [50char] “title” replaced with some event details like: “JB Ref”

*Pardon my crude syntax as I know it’s not Applescript, just that I expect anyone here to recognize what I’m suggesting.

Here is starting point I wrote one time. Edit it for your needs:


set SourceCalendarName to "Calendar"
set DestinationCalendarName to "egon"

tell application "Calendar"
	
	set sourceCalendar to calendar SourceCalendarName
	set destinationCalendar to calendar DestinationCalendarName
	
	-- Clear the destination calendar
	delete events of destinationCalendar
	
	-- Copy sources to destination --
	repeat with anEvent in (get events of sourceCalendar)
		
		tell anEvent
			set |allday event| to allday event
			set |start date| to start date
			set |end date| to end date
			set |url| to url
			set |location| to location
			set |recurrence| to recurrence
			set |description| to description
			set |excluded dates| to excluded dates
			set |stamp date| to stamp date
			set |summary| to summary
		end tell
		
		tell destinationCalendar
			set newEvent to (make new event at end of events with properties {allday event:|allday event|, start date:|start date|, end date:|end date|})
			tell newEvent
				if not (|url| is missing value) then set url to |url|
				if not (|location| is missing value) then set location to |location|
				if not (|recurrence| is missing value) then set recurrence to |recurrence|
				if not (|description| is missing value) then set description to |description|
				if not (|summary| is missing value) then set summary to |summary|
				if not (|excluded dates| is missing value) then set excluded dates to |excluded dates|
				if not (|stamp date| is missing value) then set stamp date to |stamp date|
			end tell
		end tell
		
	end repeat
end tell

Thanks! I will give it a start with this… Much appreciated!