I am unable to show variable values from within a HUD using the {}
syntax as indicated in the help text. I tried a few of the ones listed here but none of them seem to work.
I'm trying to create an hourly chime which also shows up as a large HUD so ideally would like to show the date/time in this HUD.
True, that is currently a limitation of the CAG/Advanced Trigger variables. I think I can add a workaround for that. I'll have a look later!
Right now you could make it work by reading the variables via Java Script and then writing them to some "normal" variable before showing the HUD.
Thanks for the prompt response!
My goal is to have the current time be shown in a HUD and spoken with one of the default voices. If I were to do it very frequently (say every 5-10 min), which of the scripting actions might be the most performant — shell, AppleScript, or JS?
I am hoping I can just trigger the HUD and the say
command directly from the script so the variable workaround won't be necessary.
The Real Java Script would be the most performant one. Here is an example:
async function speakTimeAndSaveToVariable() {
// Get the current time in a common US format (hh:mm AM/PM)
const now = new Date();
const hours = now.getHours();
const minutes = now.getMinutes();
const ampm = hours >= 12 ? 'PM' : 'AM';
const formattedHours = hours % 12 || 12; // Convert 24-hour format to 12-hour format
const formattedMinutes = minutes < 10 ? '0' + minutes : minutes; // Add leading zero if needed
const theCurrentTime = `${formattedHours}:${formattedMinutes} ${ampm}`;
// Run the shell script to speak the time
runShellScript({ script: `say ${theCurrentTime}` });
// Set the string variable with the current time
set_string_variable({ variableName: "currentTime", to: theCurrentTime });
}
However I recommend to use this in combination with the show hud action and a variable because it makes formatting easier. This example speaks the time and sets the variable "currentTime". This you can then use in a "show hud" action that follows:
In case you need to call the HUD from JS as well you can do it like this:
await trigger_action({json: JSON.stringify({
BTTPredefinedActionType: 254,
BTTHUDActionConfiguration: '{\"BTTActionHUDBlur\":true,\"BTTActionHUDBackground\":\"0.000000, 0.000000, 0.000000, 0.000000\",\"BTTIconConfigImageHeight\":100,\"BTTActionHUDPosition\":0,\"BTTActionHUDDetail\":\"\",\"BTTActionHUDDuration\":0.89999997615814209,\"BTTActionHUDDisplayToUse\":0,\"BTTIconConfigImageWidth\":100,\"BTTActionHUDSlideDirection\":0,\"BTTActionHUDHideWhenOtherHUDAppears\":false,\"BTTActionHUDWidth\":220,\"BTTActionHUDAttributedTitle\":\"{\\\\rtf1\\\\ansi\\\\ansicpg1252\\\\cocoartf2820\\n\\\\cocoatextscaling0\\\\cocoaplatform0{\\\\fonttbl\\\\f0\\\\fnil\\\\fcharset0 Menlo-Regular;}\\n{\\\\colortbl;\\\\red255\\\\green255\\\\blue255;\\\\red138\\\\green41\\\\blue169;}\\n{\\\\*\\\\expandedcolortbl;;\\\\cssrgb\\\\c61569\\\\c26667\\\\c72157;}\\n\\\\pard\\\\tx560\\\\tx1120\\\\tx1680\\\\tx2240\\\\tx2800\\\\tx3360\\\\tx3920\\\\tx4480\\\\tx5040\\\\tx5600\\\\tx6160\\\\tx6720\\\\pardirnatural\\\\qc\\\\partightenfactor0\\n\\n\\\\f0\\\\fs48 \\\\cf2 \\\\{currentTime\\\\}}\",\"BTTActionHUDBorderWidth\":0,\"BTTActionHUDTitle\":\"\",\"BTTActionHUDHeight\":220}',
}), wait_for_reply: true});
The CAG variable issue is now fixed in v4.871 (uploading)
Thanks, that's exactly what I imagined. And it works well.
I ended up making one more change and got stuck somehow — to a point where BTT is now constantly crashing.
The CAG variable issue is now fixed in v4.871
I wasn't too sure if you meant the regular variables or the built-in ones too. So I added the {current_hour}
to the HUD to test and my repeating time was set to every 5 seconds It made BTT crash and it crashes within 5 seconds of a relaunch now. Does BTT have a safe mode
?
Update: I was able to finally fix it thanks to the sync settings feature! I used another mac to disable it hoping there would be enough time within those 5 seconds for the change to sync through.
And it worked.
ah weird, I’ll check what’s wrong with that variable - probably number based variables are causing issues
safe mode can be enabled with this terminal command:
defaults write com.hegenberg.BetterTouchTool BTTSafeModeEnabled YES
1 Like