AppleScripts to create Calendar Events not working in Catalina I have a number of AppleScripts that are triggered by Mail.app rules. They were working perfectly (and still are) on my old iMac running High Sierra, but I now have a new iMac running Catalina on which they are no longer working.
An example script is the one below which extracts some details from the email and then creates a Calendar event containing those details and adds a couple of alarms to the event.
-- Triggered by Mail rule.
using terms from application &quot;Mail&quot;
    on perform mail action with messages theMessages for rule theRule
        tell application &quot;Mail&quot;
            repeat with theMessage in theMessages
                try
                    set msgsubject to subject of theMessage
                    set msgcontent to content of theMessage
                    set msgid to message id of theMessage
                    set {amount, dueon} to my parseMsg(msgcontent)
                    my createEvent(msgsubject, msgid, amount, dueon)
                end try
            end repeat
        end tell
    end perform mail action with messages
end using terms from


-- Parse the email content to extract invoice details.
on parseMsg(msgcontent)
    set amount to extractBetween(msgcontent, &quot;Invoice for&quot;, &quot;due by&quot;)
    set dueon to extractBetween(msgcontent, &quot;due by&quot;, &quot;Review&quot;)
    return {amount, dueon}
end parseMsg

-- Extract the substring from between two strings
to extractBetween(theString, startText, endText)
    set tid to AppleScript's text item delimiters
    set AppleScript's text item delimiters to startText
    set startComps to text items of theString
    set AppleScript's text item delimiters to endText
    set endComps to text items of second item of startComps
    set AppleScript's text item delimiters to tid
    return trim(first item of endComps)
end extractBetween

-- Trim all whitespace from start and end of a string
on trim(theString)
    set theChars to {&quot; &quot;, tab, character id 10, return, character id 0, character id 8232}
    repeat until first character of theString is not in theChars
        set theString to text 2 thru -1 of theString
    end repeat
    repeat until last character of theString is not in theChars
        set theString to text 1 thru -2 of theString
    end repeat
    return theString
end trim


-- Create a calendar event for the specified invoice.
on createEvent(msgsubject, msgid, amount, dueon)
    set startdate to (current date) + 28 * days
    set sentdate to current date
    -- set enddate to startdate
    tell application &quot;Calendar&quot; to tell calendar &quot;Invoices&quot;
        set theEvent to make new event with properties {start date:startdate, summary:&quot;Check &quot; &amp; msgsubject, allday event:true}
        delay 5
        set description of theEvent to amount &amp; return &amp; &quot;Due on: &quot; &amp; dueon &amp; return &amp; &quot;Sent on: &quot; &amp; sentdate
        delay 5
        set url of theEvent to &quot;message:&quot; &amp; &quot;%3c&quot; &amp; msgid &amp; &quot;%3e&quot;
        delay 10
        tell theEvent
            -- Add a email alarm
            make new mail alarm at end of mail alarms with properties {trigger interval:10}
            delay 10
            make new sound alarm at end of sound alarms with properties {trigger interval:370, sound name:&quot;Sosumi&quot;}
        end tell
    end tell
end createEvent

The following Mail.app Rule triggers the script
I have also enabled access to the Calendar for Mail.app in the Privacy Panel of System Preferences.

The rule tries to run as I see a little gear icon appear in the menu bar and the Calendar.app opens, but the calendar event isn’t added. As I say, this works perfectly in High Sierra. I also have a corresponding AppleScript that removes the alarms from the Calendar when an alternative email is received. Again this one works in High Sierra but dosen't work in Catalina either.
Has anyone got any ideas?
Thanks,
Alan.
OK, I've made some changes so that I can run the Script in Script Editor (by giving the variables plain text strings rather than extracting them from the email).
When I run the script I get the following error:
error &quot;Calendar got an error: Can’t get calendar &quot;Invoices&quot;.&quot; number -1728 from calendar &quot;Invoices&quot;
That gives me a clue I guess - although the Calendar that it should be adding the event to does exist in my Calendar app. Could it be something to do with the quotes around &quot;Calendar&quot; and &quot;Invoices&quot; in the following line of the script?
tell application &quot;Calendar&quot; to tell calendar &quot;Invoices&quot;