Local Storage for Macros
Macros can Now Remember Settings and Other Data
An update for Onetastic is available today with two new functions to read and write data on the local computer, similar to how Windows Registry works. This is called Local Storage. Data stored in Local Storage is available across multiple executions of the same macro. These new functions are:
- LocalStore_Write: Saves given key-value pair for this macro on the local computer. The value can be retrieved later using LocalStore_Read function even in a subsequent execution of this macro.
- LocalStore_Read: Reads value stored under the given key for this macro on the local computer. Returns true if the key has been found and the value is stored in the out parameter, false otherwise. The value must have been stored previously using LocalStore_Write function in either the current or a previous execution of this macro.
These can be used to save any data type other than an Object. If it is an Array, it cannot contain Objects.. The data is stored in a key-value pair store on the computer and is available from the same macro in the current or subsequent executions. See more info on how to use these functions in the documentation.
Saving Macro SettingsOne very useful way to use this persistent data is to store and remember user input for subsequent executions of a macro. For instance Search & Replace macro remembers the values user entered in the dialog box so that it can present those same values when the user runs the macro again. Similarly settings in a macro, like which day of the week the calendar should start for Insert Monthly Calendar macro, can be stored and retrieved.
These and a few more macros are already updated to take advantage of this. This will greatly improve usability of these macros, so that if you are using them with non-default settings, you won't have to keep changing the settings, or if you use Search & Replace multiple times with same values, you won't have to re-type them.
Debugging Local StorageObject Browser in Macro Debugger will display the values stored under the Local Storage section at the bottom: