Automators 1: Automating Calendar Events

I don`t use Fantastical on my Mac, so I adapted the AppleScript @Sal made to create the multiple events from the Numbers sheet directly in stock Calendar app. The underlying Numbers sheet from @RosemaryOrchard had to be adapted slightly, you can find it here (Dropbox link).
To use it, just fill in or copy your events in the Numbers sheet. The event end date is calculated, just fill in duration (in minutes). Also the event alarm needs to be entered in minutes. Once you’re done, select the rows you want to make into events and run the script.
I learned a lot while writing and debugging the script, thanks a lot, Sal, for the guidance your script gave me.


tell application "Numbers"
    activate
    try
        if not (exists document 1) then error number 1000
        tell document 1
            try
                tell active sheet
                    set the selectedTable to ¬
                        (the first table whose class of selection range is range)
                end tell
            on error
                error number 1001
            end try
            tell selectedTable
                set theseRows to the rows of selection range
                repeat with i from 1 to the count of theseRows
                    set cellValues to the value of every cell of item i of theseRows
                    set theEventName to first item of cellValues
                    set theStartDate to third item of cellValues
                    set theEndDate to fifth item of cellValues
                    set theAlarm to seventh item of cellValues
                    set theNotes to sixth item of cellValues
                    set theLocation to second item of cellValues
                    set theCalName to eighth item of cellValues
                    tell application "Calendar"
                        tell calendar theCalName
                            set theEvent to make new event with properties {summary:theEventName, start date:theStartDate, end date:theEndDate, location:theLocation, description:theNotes}
                            tell theEvent
                                make new display alarm at end with properties {trigger interval:-theAlarm}
                            end tell
                        end tell
                    end tell
                end repeat
            end tell
        end tell
    on error errorMessage number errorNumber
        if errorNumber is 1000 then
            set alertString to "MISSING RESOURCE"
            set errorMessage to "Please create or open a document before running this script."
        else if errorNumber is 1001 then
            set alertString to "SELECTION ERROR"
            set errorMessage to "Please select a table before running this script."
        else
            set alertString to "EXECUTION ERROR"
        end if
        display alert alertString message errorMessage buttons {"Cancel"}
        error number -128
    end try
end tell
5 Likes