iosshortcutsirishortcutsios-shortcut

Return first calendar event of each day in a chosen period


I’m building an iOS shortcut that finds all events in a specified calendar for a chosen time period (start and end date). The result is then iterated through each event with a few actions that ultimately creates a dictionary of keys and values for each found event. This is then passed as a JSON url scheme for import to an app.

Problem: In addition, I’d like it to also filter out the first event that occurs each day in order to add an additional key:value pair in the dictionary. How do I do that?

Example: A calendar full of flights used by a pilot. Shortcut asks for a start and end date and look for some criteria between those dates in order to return each flight. Say I select 7 November to 10 November. It finds 3 flights day 1, 4 flights day 2, 4 flights day 3, no flights last day. All events are needed when iterated through each to create a dictionary that later results in a JSON url file for export. But it also needs to find which of all the events that is the first flight each day (regardless of number of following flights). This is going to be used to figure out the check-in time before the first flight each day and set that as a separate key/value pair in the dictionary for only those flights.

This is what I have so far: FTL Calc import shortcut Everything I have is working as intended, but I want to add this check-in feature as well. Later on also check-out (similar for the last flight each day but I assume the technique is going to be identical)


Solution

  • After a lot of experimenting, I found one way to do it:

    1. Count number of days in selected period and make a repeat that many times (contrary to repeat for each item/calendar event).
    2. Make a function to step through one day at a time for each repeat.
    3. Search for calendar events, save into a list
    4. List function now allows to get first item each time the repeat runs. Apply actions to that item.

    I don’t know if it’s the most clever or effective way but it solved my problem.