Way to save json stringified object to preset instead of using set_persistent_string_variable

So, I found this really cool code to save settings or other preference data directly into a BTT Trigger object.

Benefit: This is great because you can bundle up the trigger (with initial settings or preference data) and deliver it with your preset bundle, which I can't see a way to deliver persistent variables in a similar way.

Is it safe to store a stringified object directly in a trigger, specifically in the BTTInlineAppleScript element? (It also works in notes and HUD detail text)

Feature: Can you make a specific element that is available on all triggers, something like BTTUserData?

Here's a code example of reading the object from the trigger, making a simple modification and then writing it back to the trigger.

async function saveToBTTTrigger() {

// get the trigger details from BTT
let trigger = await callBTT('get_trigger', {
    uuid: 'DC7BA45E-EB3E-4EBE-82BF-DD396003BA28'
})

// get the needed element
let result = JSON.parse(trigger).BTTInlineAppleScript;

// strange, have to parse again to get a usable js object
let obj = JSON.parse(result);

// reference the new object to show the hour
console.log(obj[0].hour);

// update the hour to 9
obj[0].hour = 9;

// tell BTT where to put the stringified object
let updateDefinition = {
    "BTTInlineAppleScript": JSON.stringify(obj)
}

// update the trigger details with my JSON object embeded in the applescript element!
callBTT('update_trigger', {
    uuid: 'DC7BA45E-EB3E-4EBE-82BF-DD396003BA28',
    json: JSON.stringify(updateDefinition)
});

};

Imprint | Privacy Policy