How to make complex Shortcuts easier with AI

richard moult
3 min readSep 8, 2022

--

MacOS shortcuts are powerful, but if you want to create custom specific logic you can spend the majority of your time trying to figure out what special commands are needed to solve your particular problem. For those not familiar with software programming this could be a real blocker into creating cool Shortcuts.

In this post I’ll explore how to use AI to shortcut the effort into creating complex shortcuts 🤨.

As of writing this blog there is a free beta AI available from OpenAI. You can join the waitlist here, and for myself I got access within 24hrs. There are a few others, not tried these those, but might be worth looking at if you want to try other things Microsoft, Bloom.

For this post I’m using OpenAI Model code-davinci-002 , temperature 0 .

In a previous post I looked at creating a more complex Shortcut involving regex and shell scripting . As I’m not too familiar with those topics and the Shortcut took me around an hour to create where 90% of the time was researching those topics.

So lets see if we can use AI to make that Shortcut a lot simpler to create.

Regex

For the previous post I needed to create a regex that validated strings of certain lengths.

Once you have access to OpenAI, open the playground set the correct settings mentioned above and input the text

“””
create only regex string that checks a length of a string is between 24 and 40 characters long
“””

AI provides the output

def check_length(string):
regex = re.compile(r’^.{24,40}$’)
return regex.search(string)

The bit you need is ^.{24,40}$ and simple drop that into a Shortcut action Match , like so.

Worth noting that the AI is still in beta, I found that if I amended the input to use # instead of """ then I’d get no result at all — so keep an eye on those things.

# create only regex string that checks a length of a string is between 24 and 40 characters long

Shell Scripting

The next thing I needed for my Shortcut was a script to inject the character “-” at position 8 in a string.

AI input

“””
shell script zsh
create stream editor script that inserts char “-” into the input at positin 8
“””

AI output

sed ‘s/./&-/8’

Copy and paste that into your Shortcut script like so and you are done.

Note — again the AI was a little sensitive, took a few mins to figure out how to express the question correctly. The key bit is to express the language type on the first line and mention stream editor in the description. But now I know that, all I need to do is keep the following as a template and add what I need at the end.

“””
shell script zsh
create stream editor script <add a description of what you need here>
“””

Summary

Having not use this AI tool like that before, it turned out that is was still quicker to play around with the AI tool than to perform the research into how regex and shell commands worked for my specific needs.

Especially for the regex having a little programming knowledge made the output a lot easier to understand and extract the key info I needed.

To take a guess, if I knew what I now know about that tool perhaps the hour it took me to create the Shortcut originally would have been a more effortless 15mins or so.

I hope this information gives you more power to create more complex shortcuts easier.

If you found this blog post helpful, you’ll love the book packed with plenty of real-world examples and AI integration — dive deep into Shortcuts.

Want more Shortcut info, try here.

--

--