Closed MakeShiftArtist closed 2 years ago
I considered this a bug because it's not behaving like I would expect it to, but you could list it as a feature request by using this to allow users to create their own functions that are called before execution of the shortcut
Things for this feedback. Unfortunately, this is actually working as intended, though I agree it is not intuitive and a bit limiting. The way it currently works is that calling triggerShortcut
will essentially just enqueue that shortcut for execution after the current one completes. It is a bit poorly named and should perhaps rather be called enqueueShortcut
for clarity. The way the app is currently architectured it is not really possible to change this behavior, but I am planning on refactoring that to enable a use case such as you describe. I will keep this issue open to track your feature request.
For now what I can suggest as a workaround is that, instead of using Scripting Shortcuts to encapsulate your callable code, you could write JS functions and set them up in the app's "Global Scripting" block, which you'll find in the app's Settings section. This code runs before every shortcut execution, so you can use it to define common logic or initialization.
See https://http-shortcuts.rmy.ch/execution-flow for the full list of steps in which shortcut execution happens. If you invoke triggerShortcut
, that shortcut will be executed only after all of these steps have completed.
As a first step here, as of version 2.13.0, the triggerShortcut
function is now renamed to enqueueShortcut
, to make this a bit less confusing.
In version 2.25.0, there will be a new function executeShortcut
, which will allow to trigger a shortcut immediately and receive its result. I'm currently working out the last bits and hope to release it within the next 2 weeks.
Some feedback after trying executeShortcut
on the beta channel.
I understand it returns the result of the request if there was one made.
Is there a way to pass some arbitrary string (or even better, data) instead if the shortcut executed does not execute a request (for example a scripting shortcut) ? Would it be hard or not desirable to add this possibility?
Currently, if you wanted to pass values from the executed shortcut back to the triggering shortcut, you'd have to do so by storing that value into a global variable using the setVariable
function and then retrieving it with the getVariable
function.
I'm considering adding a better mechanism to allow just returning a value directly, but that most likely won't be part of the 2.25.0 release.
This is now being released as part of version 2.25.0. For details see https://http-shortcuts.rmy.ch/scripting#execute-shortcut Regarding being able to return a value: I added this as an idea to my backlog.
Steps To Reproduce
Expected behavior The trigger shortcut should complete before the execution of the current shortcut, so that you can have create your own functions just by using the "triggerShortcut" method.
Actual behavior The shortcut runs the shortcut in before execution, but considers the called shortcut done before it actually finishes. A fix for this specific use case would be just creating a text prompt variable and using that instead of a constant, or just rewriting your shortcut script in your "before execution" instead of calling it, but this doesn't solve the general use case of creating your own functions using scripting shortcuts
Screenshots If applicable, add screenshots to help explain your problem.
Context (please complete the following information):