It is possible for KM to detect today's (apple) calendar events?

I want to execute some actions based on whether or not specific calendar event is due in next x hrs.
Is it possible?

In my case, I want to append a line (Duration of the event - Name of the event) to a text file if a specific calendar event is due today. Thus, I need such a list of event duration and name in a text file about the all the calendar events due today.

It would be great if there is a choice to choose which calendars to seek for. Because I have multiple calendars and events from some calendars may not be relevant to my purpose. Here's what I mean by multiple calendars:

Screenshot 2023-04-02 at 10.41.56

Have you looked into Apple's Shortcuts app. Lots of calendar actions.
In KM you can use 'Execute Shortcuts' action, then dump into a variable and go from there.

2 Likes

Hi, @fluid_eye. As @Steve_E suggested, a macOS Shortcuts application shortcut can be combined with a Keyboard Maestro application macro to achieve your objective. Specifically:

  • In Shortcuts check out the action named Find Calendar Events; with it, you can specify a range of dates (which can include times). You can add additional filters which can include the Calendar(s). With that filter values you could hard code the filter, specify Ask Each Time or use a variable from above action (e.g., the result of a Choose from List action). As an example, I have a shortcut that checks four of my calendars and sends me a text message that includes all entries for the following day (between Specified Dates: Tomorrow 00:00 to Tomorrow 23:59).

  • To combine data from shortcuts and macros, I suggest you check out one of my earlier posts: Keyboard Maestro and macOS Shortcuts—Data Transfer Examples - Tips & Tutorials

Good luck. If you have any follow-up questions, feel free to ask.

2 Likes

Picking up on @Steve_E and @_jims really good suggestion to use an Apple Shortcut to get the list of today's Calendar Events into a Keyboard Maestro Variable, here is an example of how that could work.

Here is the Apple Shortcut (click on the link to download):
https://www.icloud.com/shortcuts/e3c4399614cc44da82a000a1bb2af31a

And here is the Keyboard Maestro Macro that calls it and gets the data into a Variable.

EXAMPLE Get List of Today's Events Using Apple Shortcut.kmmacros (3.5 KB)

3 Likes

That works for me. This is a huge help. You're a star. Thank you so much.

And Thank you @Steve_E for your initial inputs. And Thank you @_jims for developing it further and showing the readiness to help further.

Because of your responses I can now also utilise the similar steps for other workflows to make them simpler. Thank you again.

@fluid_eye, even though it doesn't directly apply, in the spirit of @Zabobon (who sets a very high bar in this forum! :grinning:), I thought I would share one of my calendar-related shortcuts, especially considering I've discovered a few Shortcut app nuances over the years.

Shortcut-image

If you care to download the shortcut, here's a link: Shortcuts


I thought I'd point out one detail in the shortcut that isn't necessary obvious.

The method used in @Zabobon's example shortcut seems more logical and is what I used for many months. But in cases where the object in the Repeat for Each action includes many items, the Combine Text method will yield a noticeable performance improvement.

3 Likes

Nice to know this workaround of "OR".

Not useful for me for this particular use case but I might definitely need to refer your answer in the future :+1: so thanks for sharing.

In that case, I wonder if you'd have something to guide me to, to include summation of durations as well. In this same use case that I mentioned in the question, I would also like to have a summation of the durations of these events. For instance if I have a list of 5 events. Duration of each event may differ. I want to see what is the total duration of these events combined. Is it possible to get that number displayed along with the list of events?
Tagging @Zabobon as well, in case he/she/they have any inputs to share.

This is the output I am currently generating. It would be great if it could also have a number showing a total combined duration of these events. Either using siri shortcuts or KM.

I use the output of siri shortcuts into a KM variable to display it in prompt for user input action

Hi @fluid_eye; do you mean:

  • latest end time - earliest start time, or
  • summation of all events: end time - start time?

If the latter, refer to the following shortcut. (I've modified my above shortcut to include the required actions.):
https://www.icloud.com/shortcuts/5933c0ffa3254630b2f59bb862cffbd3

1 Like

That works. You're amazing.
Can't thank you enough.

I wish I could highlight your response as well to give you credit and express my gratitude. but it seems we can only put one response as a solution to our question. But your response means a lot to ME. Thank you.

1 Like

Hi, @fluid_eye. Glad that helped; however, after giving this a little more thought, I made two revisions that you might find useful.

  1. Exclude All Day events from the Summation of Durations.

    Click to expand/collapse

  2. Format the Summation of Durations in HH:MM.

    Click to expand/collapse


Here's a link to the revised shortcut:
https://www.icloud.com/shortcuts/7c612612778f41c0b7ee4fb06c7a677c

Whoa I just found a siri shortcuts genius !

Let me know if you are active on any other forums with regards to siri shortcuts or if you create content (A YouTube channel etc) about it. I'd love to follow you.

Ha, not a genius; far from it, just a guy with experience (and many scars). :stuck_out_tongue_winking_eye:

Since you said active I should probably just say that I'm not. :grinning:

But will a big disclaimer, I'll share this:


Disclaimer: Since iOS 14, I’ve cut way back on my shortcut development*. Although many of the macros I’ve shared on RoutineHub still function as expected, I’ve not officially tested any beyond the versions noted in the Information section of each post.

*With each version of iOS and macOS, Apple tends to break key features of shortcuts and the Shortcuts applications; sometimes they fix them, but many times they don’t. It’s been very frustrating and a stark contrast to Keyboard Maestro which is always rock solid and has great support.

2 Likes