The lower dictionary is what gets passed into the Memory shortcut to store the data.One of the best things about the iPad is the possibility to add accessories to it, including Apple’s own Magic Keyboard. In example 2 the dictionary at the top is what I want to store in the payload you can see it referenced in the lower dictionary payload field. Example 2 shows how to add data to storage. Example 1 shows how to get a variable from storage (variable is called Cycle Log). If adding a variable to store the variable payload is added to the master dictionary using variable name as the key and the master dictionary is stored in the reminder note.īelow are screenshots of dictionaries for passing into the Memory Shortcut. If getting a stored variable the payload value is returned. “payload” | a string, number or dictionary – the data being stored for this variable.“method” | a string specifying if the variable is being added to memory “add” or being retrieved “get”.The dictionary has three key-value pairs: Whenever I want to work with a variable that needs to persist across shortcut runs I use the Run Shortcut action and call Memory passing in a dictionary specifying if I am getting the last stored value of the variable or updating its value. I made a dedicated Shortcut whose sole purpose is to get or add persistent variables by storing them in a reminder note in a reminder list called Reference. So I’ve harnessed a useful feature of Shortcuts app to make persistent variables more readily accessible. Repeating the above steps across multiple shortcuts would prove tedious. Generalising this process to expand its usefulness Set variable name to updated variable in master dictionary, then set the reminder notes to the master dictionary. To store an updated variable I add the variable back to the master dictionary using the same variable name as its key, e.g. Once the variable is extracted from the reminder (the above processes are very fast btw) I can then do what I need with it – show it in a prompt for input or do a calculation with it etc.The dictionary value itself can be anything – including another dictionary – so the scope for storing variables can extend to cover some complex scenarios.Get value for variable name from dictionary name. One of the dictionary keys is the variable name I’m interested in, so I get the value of that key.Then it gets the content of the notes of that reminder and extracts a dictionary from the note text.When I run my Shortcut it gets that reminder by name (filters to first reminder match).In that list I have a reminder called PyLog variables.This list will only ever have reminders that I use for variable storage so it won’t become unwieldy. In Reminders I’ve created a dedicated list called Reference. In the prompt is the previous reading, e.g. When adding a new meter reading the Shortcut will ask if it is an electricity / gas reading, and then it will prompt me for the reading. The Shortcut is called PyLog (because the Shortcut triggers a Python script to store my readings in text files). Here’s how I implement variable storage for a Shortcut I use to log electricity and gas meter readings. > This is my preferred method of storing variables across Shortcut runs because I always have the Reminders app installed and it’s more efficient than the Notes method. To do this we can simply use the Edit Reminder action. So variables can be stored in a master dictionary* as text. Reminders might seem a strange place to store data until you consider the fact that reminder notes can be changed not just be appended to. > The above limitation also applies to storing variables in text files directly by a Shortcut – Shortcuts can only append to text files. Eventually this will have an impact on the performance of the Shortcut. Also as the Shortcut is used over time the note contents will increase. This means you have to build in a routine to identify the last item that was appended to get the latest data payload. Once data is inserted into the note it can’t be deleted by Shortcuts. > The major limitation here is that Shortcuts can only append to a note. Set the limit to 1 note and assign it to a variable. Just give a note a unique title and you can reliably access it using the Find Notes Where action. So a note can serve as a data repository. I’d judge that a high proportion of iOS users have the stock Notes app installed. > This is good but I personally wanted something that wouldn’t require an app that I might not have installed all the time. Global variables are included in the free set of functionality. This app supports a feature called Global Variables and these are available across Shortcut runs.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |