# Launch Mac Shortcut

**URL:** <https://forum.xojo.com/t/launch-mac-shortcut/68185>\
**Category:** General\
**Created:** [January 27, 2022, 1:04am UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185 "2022-01-27T01:04:10Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Livingston](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_livingston/32/255_2.png) [@Robert\_Livingston](https://forum.xojo.com/u/Robert_Livingston)\
**Post date:** [January 27, 2022, 1:04am UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/1 "2022-01-27T01:04:11Z")

</div>

My goal is to launch a Mac Shortcut (Shortcuts App) from Xojo knowing the name of of the Shortcut.

When I was practicing, trying to understand the topic, I learned how to successfully launch a Shortcut from the Terminal with a command. I have read about but not really understood URL Schemes. I am willing to do more reading here if URL schemes are somehow the way to go. Apparently you can launch a Shortcut with a URL Scheme.

What I am looking for is the simplest, most straightforward way to launch a Shortcut from within Xojo. Any help appreciated.

---

<div class="post-metadata">

**Author:** ![Robert\_Livingston](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_livingston/32/255_2.png) [@Robert\_Livingston](https://forum.xojo.com/u/Robert_Livingston)\
**Post date:** [January 27, 2022, 9:28pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/2 "2022-01-27T21:28:17Z")

</div>

I do not know if the below is the _best_ way of accomplishing the task but it works.

_Say Hi_ is the name of the Shortcut that is being fired off.

```auto
Var DQ As String = Encodings.UTF8.Chr(34)
Var theCommand As String
theCommand ="shortcuts run "+DQ+"Say Hi"+DQ
Var mShell As Shell
mShell = New Shell
mShell.ExecuteMode=Shell.ExecuteModes.Synchronous
mShell.Execute(theCommand)

```

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [January 27, 2022, 9:33pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/3 "2022-01-27T21:33:10Z")

</div>

What’s wrong with:

```auto
theCommand = "shortcuts run ""Say Hi"""

```

---

<div class="post-metadata">

**Author:** ![Robert\_Livingston](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_livingston/32/255_2.png) [@Robert\_Livingston](https://forum.xojo.com/u/Robert_Livingston)\
**Post date:** [January 27, 2022, 11:22pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/4 "2022-01-27T23:22:04Z")

</div>

Nothing. 🤔

Except my unawareness.

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [January 28, 2022, 11:48pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/5 "2022-01-28T23:48:30Z")

</div>

> [@TimStreater](#):
>
> `theCommand = "shortcuts run ""Say Hi"""`

or you could use single quotes, which can be easier:

`theCommand = "shortcuts run 'Say Hi'"`

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [January 29, 2022, 11:33am UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/6 "2022-01-29T11:33:08Z")

</div>

> [@Robert\_Livingston](#):
>
> Mac Shortcut

I do not know what is `Mac Shortcut`.

Is it possible for someone to explain ?

I searched with Google, but only found Menu keyboard shortcut…

---

<div class="post-metadata">

**Author:** ![TimStreater](https://forum.xojo.com/user_avatar/forum.xojo.com/timstreater/32/586_2.png) [@TimStreater](https://forum.xojo.com/u/TimStreater)\
**Post date:** [January 29, 2022, 11:40am UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/7 "2022-01-29T11:40:39Z")

</div>

I assumed they were talking about aliases.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [January 29, 2022, 12:41pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/8 "2022-01-29T12:41:02Z")

</div>

Thank you Tim. OK.

But how the shared code is related to alias is… lost in the dark web.

---

<div class="post-metadata">

**Author:** ![Mike\_D](https://forum.xojo.com/user_avatar/forum.xojo.com/mike_d/32/266_2.png) [@Mike\_D](https://forum.xojo.com/u/Mike_D)\
**Post date:** [January 29, 2022, 2:47pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/9 "2022-01-29T14:47:56Z")

</div>

It’s an app :

> **[Intro to Shortcuts on Mac](https://support.apple.com/guide/shortcuts-mac/intro-to-shortcuts-apdf22b0444c/mac)**
>
> Shortcuts is an app that lets you create powerful task automations called shortcuts.

And also a command line tool you can run in the Shell:

> **[Run shortcuts from the command line](https://support.apple.com/guide/shortcuts-mac/run-shortcuts-from-the-command-line-apd455c82f02/5.0/mac/12.0)**
>
> You can run a shortcut from the command line on your Mac.

---

<div class="post-metadata">

**Author:** ![Emile\_Schwarz](https://forum.xojo.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@Emile\_Schwarz](https://forum.xojo.com/u/Emile_Schwarz)\
**Post date:** [January 29, 2022, 2:54pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/10 "2022-01-29T14:54:47Z")

</div>

Thank you.

---

<div class="post-metadata">

**Author:** ![Robert\_Livingston](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_livingston/32/255_2.png) [@Robert\_Livingston](https://forum.xojo.com/u/Robert_Livingston)\
**Post date:** [July 20, 2022, 8:17pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/11 "2022-07-20T20:17:18Z")

</div>

As has been established, in this context we are talking about Mac _Shortcuts_ which is an application provided by Apple in recent OS’s that allows the user to combine multiple steps from various apps to accomplish a task. Users can create a library of pre-built Shortcuts.

I have an application that itself wishes to call individual Shortcuts. It is possible to use the Shell.Execute command to fire off a Shortcut. I have the following code in a Xojo application to launch a Shortcut. You need the name of the shortcut. A Shell executes the Shortcut of the name that is passed.

Shell.Execute(“shortcuts run “+”“nameOfShortcut””) \ the basic form of the command

I am using the code below which allows me to pass any Shortcut that I have in my library by its name (whichShortcut)

```auto
Var nameQuote As String
nameQuote = UTF8.DQ + whichShortcut + UTF8.DQ
Var theCommand As String
theCommand = "shortcuts run " + nameQuote
Var theShell As Shell
theShell = New Shell
theShell.ExecuteMode = Shell.ExecuteModes.Synchronous
theShell.Execute(theCommand)

```

This works fine if I pass a simple Shortcut. Now a Shortcut can complete its task without any input from the user. I consider these “simple”.

But there are also Shortcuts that ask the user for additional information. One of my test Shortcuts is designed to email a recently taken photograph to a recipient. It prepares an email with a chosen photograph as an attachment and this pending email is presented to the user. At this point the user can for example add some verbiage to the email and then click on the send button. It would be possible for the Shortcut to then continue on doing various tasks. But the essential fact is that the Shortcut has “paused” and is waiting for the user to do something.

However, I (Xojo) get an error message which I believe is related to the fact that the Shortcut is complicated enough to ask for additional user input. The Error code is — _Error 134_. I check for this error after the Shell.Execute command.

```auto
If theShell.ExitCode = 0 Then
  // all is well
Else
  MessageBox("Error Code: " + theShell.ExitCode.ToString)
End If

```

With my limited testing, it seems to me that these Shortcuts that “pause” at some point to get more information are the Shortcuts that create this error. In some cases, the Shortcut actually does its task successfully despite my code getting sent an error message but that is often not the case and the situation is not satisfactory.

Has anyone successfully employed Shell commands to launch a Shortcut? Are there any suggestions of how to avoid this error? Or what causes it?

---

<div class="post-metadata">

**Author:** ![Robert\_Livingston](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_livingston/32/255_2.png) [@Robert\_Livingston](https://forum.xojo.com/u/Robert_Livingston)\
**Post date:** [July 20, 2022, 10:30pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/12 "2022-07-20T22:30:07Z")

</div>

By the way, when I launch the shortcut that returns an error from Xojo from Terminal, it works without a problem.

```auto
pig@Roberts-Mac-Studio ~ % shortcuts run "Send Recent Photo to Pam"

```

---

<div class="post-metadata">

**Author:** ![AlbertoD](https://forum.xojo.com/letter_avatar_proxy/v4/letter/a/dbc845/32.png) [@AlbertoD](https://forum.xojo.com/u/AlbertoD)\
**Post date:** [July 20, 2022, 10:41pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/13 "2022-07-20T22:41:04Z")

</div>

What error?  
Not found?  
Try using the full path to shortcuts.

---

<div class="post-metadata">

**Author:** ![Robert\_Livingston](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_livingston/32/255_2.png) [@Robert\_Livingston](https://forum.xojo.com/u/Robert_Livingston)\
**Post date:** [July 20, 2022, 11:35pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/14 "2022-07-20T23:35:59Z")

</div>

The Error Code is 134. I do not know exactly what the error is.

It is finding the Shortcut just fine. The Shortcut will actually run. In my experience, if there are no user interactions, it will be fine. If there is just one interaction with my small sample they might work although I get an error message. When I have expanded the shortcut to require two interactions with the user, it will not work at all.

The command that you are using in Xojo is not the name of a file. Individual Shortcuts are accessed through the _Shortcuts_ app. They are not individual files.

This is the command:

theShell.Execute(“shortcuts run ““nameOfIndividualShortcut”””)

---

<div class="post-metadata">

**Author:** ![Robert\_Livingston](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_livingston/32/255_2.png) [@Robert\_Livingston](https://forum.xojo.com/u/Robert_Livingston)\
**Post date:** [July 20, 2022, 11:53pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/15 "2022-07-20T23:53:14Z")

</div>

```auto
If theShell.ExitCode = 0 Then
  // all is well

Else
  MessageBox("Error Code: " + theShell.ExitCode.ToString)
End If

```

Maybe the code above is the issue. Perhaps I am asking for trouble. Things do better if I avoid looking for the error. I just skip the code that produces the message things seem to go smoothly with my limited testing. It does make me feel uncomfortable that an error is being created even if I do not see it. 🙈

---

<div class="post-metadata">

**Author:** ![Arnaud\_N](https://forum.xojo.com/user_avatar/forum.xojo.com/arnaud_n/32/21824_2.png) [@Arnaud\_N](https://forum.xojo.com/u/Arnaud_N)\
**Post date:** [July 21, 2022, 8:03am UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/16 "2022-07-21T08:03:30Z")

</div>

> [@Robert\_Livingston](#):
>
> With my limited testing, it seems to me that these Shortcuts that “pause” at some point to get more information are the Shortcuts that create this error.

To me, this sounds like the shell is waiting for more input, as if your parameter was “truncated”. Are you surrounding “nameQuote” with appropriate quotes?

---

<div class="post-metadata">

**Author:** ![Jeremy\_Jefferies](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/ecccb3/32.png) [@Jeremy\_Jefferies](https://forum.xojo.com/u/Jeremy_Jefferies)\
**Post date:** [July 22, 2022, 9:53pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/17 "2022-07-22T21:53:19Z")

</div>

If you’re doing this in a desktop app you can use

```auto
showurl("shortcuts://run-shortcut?name=OpenXojo")

```

Fastest way I found via terminal/console app is to use

```auto
dim s as new shell
s.Execute("open shortcuts://run-shortcut?name=OpenXojo")

```

You can replace any spaces between words with %20 as it follows typical URL rules too.

```auto
dim mystring as string = "Open Xojo"
mystring = mystring.replaceall(" ","%20")
showurl("shortcuts://run-shortcut?name=" + mystring)
// which would convert the URL to "shortcuts://run-shortcut?name=Open%20Xojo"

```

Here’s a good article that answers how you do other things such as passing in input etc [The Complete Beginner’s Guide to Apple Shortcut Deep Linking for Developers | by ■■■■■■■ Shah | Infonity Tech | Medium](https://medium.com/infonity-tech/shortcut-deeplinking-for-ios-developer-64f75171c7de)

You can use callbacks to somewhat customise what happens depending on if the shortcut succeeds or fails.

Hope it helps 🙂

Edit:  
If you go the route of using “shortcuts run” you can type “man shortcuts” into the terminal to get a little help file that tells you a little more of how to handle input and output.

Edit 92:  
If you don’t want the shortcut app to open when you use URLs add **&silent=true** to the end of your url.

---

<div class="post-metadata">

**Author:** ![Robert\_Livingston](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_livingston/32/255_2.png) [@Robert\_Livingston](https://forum.xojo.com/u/Robert_Livingston)\
**Post date:** [July 23, 2022, 6:10am UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/18 "2022-07-23T06:10:48Z")

</div>

This is a Desktop app.  
Quite interesting. Do you have an opinion as to which approach Is best?

1. Create new Shell & Execute  
OR
2. Using URL schemes

Both seemed to work when I tried them. And I did not get an error message using the Shell/Execute approach. So it seems superior to my original approach. My own inclination is to use #1.

> If you don’t want the shortcut app to open when you use URLs add **&silent=true** to the end of your url.

I am not sure how that would apply. It seems in my use case Shortcuts **has** to open.

I really appreciate the input.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Jefferies](https://forum.xojo.com/letter_avatar_proxy/v4/letter/j/ecccb3/32.png) [@Jeremy\_Jefferies](https://forum.xojo.com/u/Jeremy_Jefferies)\
**Post date:** [July 23, 2022, 11:52am UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/19 "2022-07-23T11:52:23Z")

</div>

Personal preference? Would be Using URL Schemes however it would really depend on what exactly the Shortcut is performing.

> [@Robert\_Livingston](#):
>
> Error Code is 134

The og 134 error sounds like it could possibly be a SIGABRT ([https://stackoverflow.com/a/23098735](https://stackoverflow.com/a/23098735))

`man signal` in the terminal can tell you more about these

I believe it’s possible to catch these and change what they do when the shell receives this request with trap [Bash trap command](https://linuxhint.com/bash_trap_command/)

`man trap`

Or maybe the shell is just timing out? The following code will set your timeout to infinity.

```auto
Var s As New Shell
s.ExecuteMode = Shell.ExecuteModes.Synchronous
s.TimeOut = -1

```

The &silent=true won’t always have a use case, its more for those shortcuts where you want to say hit a button to have your brightness change but don’t want the Shortcut App to bounce/activate into your dock bar getting in the way of what you’re working. More of a User Experience thing than a functionality thing.

---

<div class="post-metadata">

**Author:** ![Robert\_Livingston](https://forum.xojo.com/user_avatar/forum.xojo.com/robert_livingston/32/255_2.png) [@Robert\_Livingston](https://forum.xojo.com/u/Robert_Livingston)\
**Post date:** [July 23, 2022, 3:05pm UTC](https://forum.xojo.com/t/launch-mac-shortcut/68185/20 "2022-07-23T15:05:57Z")

</div>

> [@Jeremy\_Jefferies](#):
>
> The &silent=true won’t always have a use case, its more for those shortcuts where you want to say hit a button to have your brightness change but don’t want the Shortcut App to bounce/activate into your dock bar getting in the way of what you’re working. More of a User Experience thing than a functionality thing.

I tried this but I was not absolutely sure whereto put **&silent=true**. I tried both of the below. (note to reader — _System.GotoURL_ and _showurl_ have identical functionality. The latter has just been deprecated. In my code, _noSpaces_ is just the name of the shortcut with spaces replaced by %20)  
The first did not suppress the appearance of the Shortcuts app. It did nothing as far as I could tell. The second resulted in the Shortcuts app appearing but the nothing happening.

```auto
System.GotoURL ("shortcuts://run-shortcut?name=" + noSpaces+"&silent=true")

```

or

```auto
System.GotoURL ("shortcuts://run-shortcut&silent=true?name=" + noSpaces)

```

Incidentally, I tried the possible suggestion

s.TimeOut = -1

That did not prevent the error message.

I had Googled and run across the

> possibly be a SIGABRT

thing, But this is/was so far out of my wheelhouse that I could not make much of this.

I hear about using URL schemes on various podcast that I follow but I had concluded in my mind that it was some kind of brilliant hack that I was not destined to understand. So my personal preference, based on uninformed intuition, is to use the non-URL technique that Jefferies suggested. In my limited testing both worked just fine.

[Next page](https://forum.xojo.com/t/launch-mac-shortcut/68185.md?page=2)
