Ah I think a better solution to this use case is to run the script periodically and update a variable if the focus mode has changed. Then you can use the " Variable Value Did Change" trigger:
Example Preset:
exported_triggers.bttpreset (13.3 KB)
Here is a slightly updated script REQUIRES BTT 4.789
async function checkFocusState() {
let focus = "No focus";
let assertions = JSON.parse(readFile("~/Library/DoNotDisturb/DB/Assertions.json"));
let modeConfigurations = JSON.parse(readFile("~/Library/DoNotDisturb/DB/ModeConfigurations.json"))
let config = modeConfigurations.data[0].modeConfigurations;
let manualFocus = assertions?.data[0]?.storeAssertionRecords;
if(manualFocus) {
const modeid = manualFocus[0]?.assertionDetails?.assertionDetailsModeIdentifier
if(modeid) {
focus = config[modeid]?.mode?.name
}
} else {
const date = new Date
const now = date.getHours() * 60 + date.getMinutes()
for (const modeid in config) {
const triggers = config[modeid].triggers.triggers[0]
if (triggers && triggers.enabledSetting == 2) {
const start = triggers.timePeriodStartTimeHour * 60 + triggers.timePeriodStartTimeMinute
const end = triggers.timePeriodEndTimeHour * 60 + triggers.timePeriodEndTimeMinute
if (start < end) {
if (now >= start && now < end) {
focus = config[modeid].mode.name
}
} else if (start > end) { // includes midnight
if (now >= start || now < end) {
focus = config[modeid].mode.name
}
}
}
}
}
let previousFocusMode = await get_string_variable("last_focus_mode");
if(previousFocusMode != focus) {
await set_string_variable({variableName: "last_focus_mode", to: focus})
}
return focus;
}
Then in the variable value did change you can have some if conditions: