I am chaining them automatically, I currently only have 2 (because of the hassle of coding the passing values).
In my drafts to organize my various drafts about the same project I link them by their UUID and by tags, to be able to preview many drafts at once.
# Script for project X
Paragraph number 1
UUID: [[uuid]] (# Important topics to hit)
Paragraph number 2
To make the link I have an action that asks me if I want to select an existing draft or create a new one. And in case is a new one it asks me for a different action that creates drafts from a template.
What I pass through
From that I’m passing through the project name, some extra tags and any selected text I had. Witch I’m writing at the first line and deleting at the end of the actions
Still not clear on the use case - how are you “chaining” actions?
Regardless, some general comments:
Each action executes in it’s own context. Scripted global variables will be available across multiple script steps in the same action.
Data can be passed between scripted steps and other types of steps which use templates using draft.setTemplateTag.
The Include Action action step can be used to embed steps from another action in the current context as if they were defined there - so if you are “chaining” to reuse scripts or other action steps, you might consider this as a better strategy so those variables are shared.
The other reliable way to store and restore values is to write and read values from files using FileManager functions.
You haven’t described yet how you automatically chain the actions together. How you do it can affect what approaches you can take.
Are you automatically chaining via an Include Action action step, a URL call with the action parameter, using App.queueAction() in a script action step, or something else, like using Shortcuts to control the flow?
Okay, because the actions are ‘queued’ to run one after the other, they won’t be in the same context; as described in Greg’s notes above.
Options to consider would be.
Change the method to something like include action, but you potentially lose any conditional branches doing that. But if you had two actions for two options and you knew which one to use at the start, this could work.
Similarly you could simply build separate actions, but you then lose reuse of actions, but if everything were script-based and loaded form file, then you could regain that.
Store your data somewhere that provides persistent storage between actions so that actions running in different contexts can share the data. Options could be:
i. In the current Draft - just like you are doing, so no change, but you must ensure you are not switching drafts between actions; which presumably to this point you haven’t.
ii. In a file in the file system - Greg references how to do this above.
iii. In the clipboard - probably the easiest way, but you do lose whatever was previously on the clipboard.
It might be that in some cases you could manipulate the draft content outside of Drafts using some sort of platform automation Shortcuts, or AppleScript (a work in progress) for example. These automation environments in turn have their own capabilities for providing data persistence.
Some methods are obviously more effort to implement, but hopefully, this summarises a set of approaches.