iOS Shortcuts App to make Calendar Events

End of the week Thinking about Automation

I’ve got a cup of tea in my hand and I’m wondering what I should do for the day. There is a little puzzle I would like to solve. This is an iOS or Mac automation problem. Each month I get an email in about the English-language films on in Platja d’Aro and I would like to have a way of automating taking the name of the film and the date and creating a calendar event. I’d like to do this with the Shortcuts application.

What would be good is if I could just send the text of the whole email to the beginning of the automation. Shortcuts would find the relevant information I want and take it to the end of the process. It will add the location information for the cinema and also add the travel time to the event. If it was just one film per month it may be a little bit easier. However, it has to find two film titles and dates in the text.

My first idea

My first idea was to select the name of the film and the date manually and copy it to the clipboard. I would then share that to a shortcut which will do the rest of the job.

It’s not even a big job to do this thing manually. I’m more interested in how to solve the problem and getting Shortcuts to do it with coding. I am prepared to find out if there’s a way to do it with JavaScript. Let’s first of all see if I can do it in a more simpler fashion before I get ankle-deep into code.

I was wondering if I could use Regular Expression to find matches for the text. The films always are on a Thursday and that word is the first word of a line of text in the email. Could be a way of getting my code to find the date in the email. It should also be possible to use regular expression to find text which is a date. More difficult to find titles because each month they vary and don’t stand out from the rest of the text in a meaningful way.

When I have this information the next trick will be to put it into a calendar. It’s possible to use the Add New Event calendar action, but I think I’m going to have more luck with using Fantastical and probably using the X-Callback URL encoding to get all of the details into the event I want to create. I’m sure it will take much trial and error to make this work. It’s amazing what you can accomplish though when you persevere.

I might also have a look at doing this automation on the Mac too. On the Mac I can use Keyboard Maestro. The good thing about using that application is I can get it to record my keystrokes as I make them. The automation then is the playback of that recording. It would be pretty good to have both ways of making this automation. Sometimes I’m sitting at my desk in front of my iMac when I see this email. Other times I’m with my iPad or my iPhone.

Banging your head against a brick wall

That’s what it feels like sometimes when you’re trying to work out how to do some coding. Especially when you are not a coder. To some extent I was doing quite well using Shortcuts on the iPad and iPhone. I could get the correct blocks necessary to make the shortcut kind of work. It seemed as though there were always just a little niggling problems to annoy me. I found Fantastical worked best when I had the title on the first line followed by the rest of information on subsequent lines. The problem came about with the information being presented with the date first, followed by the title. It then didn’t put all of the title into Fantastical. Getting more complicated by the minute.

This led me to find ways of automating getting the two parts of the data onto separate lines and in the right order. I looked at ways of doing this within the Shortcuts app. Then I tried to get that same job done in Drafts and I also ended up working out how to do it in Editorial. It got quite confusing going from one app to another trying to get the same thing done. Had to deal with different notation for the actions in each app. My preference was still to do everything within Shortcuts in order to make it as simple as possible. On the other hand, I was able to get Shortcuts to send data out to Editorial and to bring it back in again after it had been rearranged. Still not working right for me though.

A twist in the story

When I was trying to work this out I did try to use a date which was in the past. When I did this, Fantastical wanted to create the event in the following year. It makes sense because why would you want to create events for something which has already taken place. Even so, I did spend some time adding things into the code to try and stop that from happening. Sometimes it worked and sometimes it didn’t. Waste of time because I will really only do this with new emails containing dates in the near future.

I couldn’t work out why on some occasions it shows a completely different date to the text being given. Fantastical he supposed to be good at using plain language to extract the data to create events. What with the title having to be first, followed by the date and then I had to put in the proper address for the location, it’s clear Fantastical needs the data to be presented in a specific order. Had to throw things out of my automation and try again multiple times.

Appending to the clipboard

What I have found works efficiently is to grab the title which is supposed to be on the first line. That goes into the clipboard first. Then there is a shortcut I found and installed into Shortcuts which will take the date which I have selected and put it on a line after the title already placed in the clipboard. The actions within the shortcut I have been making takes the data and then adds the address for the cinema and throws it all into Fantastical. It works, but still is not as automatic as I would like it to be. Not the final solution as it was not automatic enough.

The road to success for my automation

I didn’t give up, but I did put the problem to one side for a day. Sometimes it’s good to do this to come back fresh and with new ideas. I went out for a drive around Barcelona hunting charging points for my electric car. In the evening time I relaxed and watched television, including the movie ‘Walk the Line’ which was a biopic based on the life story of Johnny Cash. I successfully put the automation problem I’d set for myself right to the back of my mind.

New day and new ideas

I found it was possible to throw in a big lump of text which included two lines which had my data into the beginning of the automation and extract just those two lines. I did this using Regular Expression. There is an action within Shortcuts which will match text and you to use a regular expression to get what you want. I had to do a bit of reading on a website which has all the information and tutorials on using Regex. To be honest it was quite complicated leading to a good bit of head scratching. In the end I was able to adjust one of the examples and try it out in an application called Expressions on my Mac. I had the text pasted into the search area of the application and I kept changing the regular expression until it selected everything I required. I got there in the end!

Working with the captured text

So now I had the text within the shortcut application but I still had the problem of getting the title of the movie in front of the date. If I didn’t do this the automation only put a couple of words into the title area for the event into Fantastical.

I found an action in Shortcuts which would split the text. The first option within this action I used was to split the two titles with dates into two lines. I didn’t need the word Thursday so I had the automation delete that word. I then split the text again using a custom search term. So this put the date on one line and the title on another line. I ended up with a list of four items.

I tried every which way I could think of to give each item in this list a variable. This would allowed me to put the two pairs of title and date together in the right order. Each time I tried the shortcut just kept getting confused. I was getting very confused myself at times. So I decided to try and split the automation into separate parts. This is a good plan because you can have a shortcut run other shortcuts. During my trials of ways to split up the text I found I could use the action ‘Get Item from the List’ to give me each of the four pieces of data. So I duplicated my shortcut so I had four of them. Each shortcut provided one of the four data points.

Bringing it all together in a controlling shortcut

So each shortcut gives me a piece of text. I started a new controller shortcut bringing in to film titles and two dates. This was easily done by running the shortcut for each data point to an action Get Text from Input and then setting a variable. I could then use each of these variables to put the text in the right order for adding an event into fantastical.

Number 3 of 4 shortcuts to parse the text for the controller Shortcut

My first attempt was to use X callback URL for sending the data to fantastical. I did it this way to add an address for the cinema to the calendar event. It didn’t work the way I wanted it to. It wanted me to confirm by tapping on the add button in fantastical for each movie.

So what did instead was to create a text output by combining three variables. Two of them from the shortcuts running in this controller shortcut and the other variable was the address of the cinema. This worked the way I wanted to work because there is a switch to turn off the editing within Fantastical. At the end of all this the shortcut runs perfectly without any extra input from me.

My shortcut automation in use

I use the email application Airmail 3. There is a small amount of automation available within this app. I created an action in Airmail which sends the content of the email to my newly created shortcut in the Shortcuts app. It all runs in the background and I don’t need to do anything else. We have a winner!

2 Replies to “iOS Shortcuts App to make Calendar Events”

  1. DavidAllenWizardgold 17/11/2018 at 9:55 am

    yesterday I got the email which gave me the dates and films for December.
    My automation didn’t work right….

    That’s just funny.

    The email included the word Thursday earlier in the email which triggered the automation too soon. That was out of the ordinary so the next one will probably be OK.

    There was s dot missing after the time it was only 20.30 instead of the 20.30. which it was based on in the previous email. I split the text using the dot and the space after it.

    I might have to adjust the actions to make the split more reliable.

  2. DavidAllenWizardgold 18/11/2018 at 8:36 pm

    I fixed the splitting of the line of text with splitting with 20.30 rather than just the space followed by a dot. I just had to replace that 20.30 in the main Shortcut. Easy done.

    As for the possibility of the word Thursday being inserted in the text before the two lines I want to capture, I’l just have to check for that when I read the email. It was rare it was there in this email.
    I did try to get the Regex to get only the lines when Thursday was at the beginning of the line. In the app I have on the Mac I managed to work it out, but in Shortcuts it must use a different regex engine and it didn’t do it.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.