Automators 1: Automating Calendar Events

Are you planning to use it with teachers or students? Curious how or why you would have to keep track of different student deadlines depending on the student. Would this be because of various student classes or groups?

Students. They sign up for the course (foods 10, 20, 30) but they do different modules based on what they want to accomplish. In a given semester, they can complete between 5 and 7, 1 credit modules that count toward graduation. The individual modules have their own assignments, tests, practical assessments, and benchmarks that must be completed before moving on to the next module. It is student-driven as to what they take (with guidance) so they will mostly all be on different timelines. Still haven’t figured out how to do it, but I have another month or so. :stuck_out_tongue_winking_eye:

1 Like

Awesome first show. Already have the first workflows up and running. I’ve had workflow installed since it was mentioned on MPU, and have played around with functions, but have had trouble really thinking about how it could be put to use. Looking forward to getting more ideas from this show.

1 Like

Such a great episode! The additional screencasts really help!

1 Like

We suspected they would be!

1 Like

This is an amazing action for Drafts 5 that uses chrono.js to parse events using natural language and then uses the Calendars API to create those events without leaving Drafts or having to flip flip between Drafts and Fantastical. This has become one of my favorite Drafts actions.

Here is a blog post explaining the action and a link to to the action itself.

6 Likes

Loved the show, but do have a problem with the use of tooling like IFTTT.
Their way to make money is unknown, so you are probably the product,
(Their privacy statement even strongly hints at that)

So I don’t know it that is the way to go…

A post was split to a new topic: Adding duplicate events to multiple days

IFTTT started to monetise partnerships a while back.

https://www.quora.com/How-does-IFTTT-make-money/answer/Aaron-Disibio-3

Great episode! Chock-full of useful information.

For those interested, here’s an AppleScript script (based upon an example at https://iworkautomation.com/numbers/table-edit.html) for parsing the selected rows of the Numbers table and adding events to Fantastical:

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 formatted value of every cell of item i of theseRows
					set calendarString to last item of cellValues
					tell application "Fantastical 2"
					    parse sentence calendarString with add immediately
					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
25 Likes

The AppleScript man himself! Thanks Sal, this is a brilliant script. :grin:

Enjoyed the first episode. I’ve never got into workflow before but I’m now inspired to give it a try and have built one that automates dialling into conference calls. Pretty happy with it! I’ll share it in the iOS section.

1 Like

I read the article, but have also read the privacy statement.
In the monitization they promise “extensive analytics” and in the statement thay indicate they can share all your data with 3rd parties, without your explicit consent. So unfortunatey for me IFTTT is a non-starter.

2 Likes

Yeah. I wasn’t noting anything about privacy. Just responding to the point you made about their way to make money being unknown.

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

I was just about to plug my Drafts action when I saw that @jmreekes had already done so above! Thanks for posting that.

Since I’m here, may as well give it another plug, and explain in more detail. It basically replicates the functionality of Fantastical natural language parsing for adding events, but directly in Drafts using the javascript calendar scripting. Especially for adding a large number of calendar events on iOS, it’s much faster than Fantastical because it doesn’t have to do the URL scheme hopping back and forth. All the events go straight into the calendar almost instantly.

Syntax is identical to Fantastical, except for recurring events, which are not currently supported (this is a limitation of the Drafts scripting capabilities).

More details in my blog post.

3 Likes

Excellent work.

Using a segment of your script, here’s an AppleScript “clean and wax” trick for getting and setting an array of values in a single line of code:

tell selectedTable
	set theseRows to the rows of selection range
	repeat with i from 1 to the count of theseRows
		set thisRow to item i of theseRows
		copy the formatted value of every cell of thisRow to ¬
			{eventName, startDate, endDate, eventAlarm, eventNotes, eventLocation, calendarName, eventString}
		tell application "Calendar"
			tell calendar theCalName
				set newEvent to make new event with properties ¬
					{summary:eventName, start date:startDate, end date:endDate, location:eventLocation, description:eventNotes}
				tell newEvent
					make new display alarm at end with properties {trigger interval:-eventAlarm}
				end tell
			end tell
		end tell
	end repeat
end tell
10 Likes

@RosemaryOrchard: Thank you for mentioning the scenario of entering information based on external (already digital!) data into a calendar. At the start of each year I used to manually put the “release dates” of magazines that I subscribe to in a separate calendar “Magazines” to know when I can expect them. I manually entered one and then duplicated/moved that one in Fantastical (getting the dates from a web page from the publisher). I now realise that a simple Drafts JavaScript action makes this much easier:

let calendar = Calendar.find("Magazines");
let text = draft.content.split('\n');
let title = text.shift();
for (line of text) {
    let date = line;
    let event = calendar.createEvent();
    event.title = title;
    event.startDate = date;
    event.endDate = date;
    event.isAllDay = true;
    if (!event.update()) {
      alert(event.lastError);
    }
}

Enter the magazine name on the first line of a new draft and copy/paste the “release dates” below. Run the action. Done! :smiley:

2 Likes

Thanks for the tip :grinning:! I suppose the variables in the array have to be in the corresponding order to the columns in the spreadsheet? In my original script they were not listed in order, since they were referenced directly. Also there is one column (duration) that needs to be skipped.

1 Like

Yup, to use the “clean & wax” trick, the order of the array variables must match the order of columns. Cheers!

2 Likes