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)
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.
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?