HELP: Applesciript Update_Trigger / Add a trigger to All Groups automatically

I'm having trouble using the Update_Trigger function to update the look of a trigger.

This escape key changes it's own style based on a settings variable. Users can choose between an 'edge' look which makes the touchbar seem bezelless at the left side or stay with the original inset button.

I've tried the tip that @Andreas_Hegenberg gave me over at my previous post, but I can't seem to get it to work.

Issue: the widget is not appearing. It's logic seems to be correct so I suspect that the update_trigger implementation isn't right.

here's the JSON for you to paste in:

Open
{
  "BTTWidgetName" : "esc (listens to settings)",
  "BTTTriggerType" : 639,
  "BTTTriggerTypeDescription" : "Apple Script Widget",
  "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
  "BTTPredefinedActionType" : 189,
  "BTTPredefinedActionName" : "ESC (Escape Key, respects pressed modifiers)",
  "BTTEnabled2" : 1,
  "BTTUUID" : "033E04C4-A3EC-4394-AF1E-D9AE145118B2",
  "BTTEnabled" : 1,
  "BTTOrder" : 0,
  "BTTDisplayOrder" : -1,
  "BTTTriggerConfig" : {
    "BTTScriptType" : 0,
    "BTTTouchBarApplyCornerRadiusTo" : 2,
    "BTTTouchBarButtonColor" : "0.000000, 0.000000, 0.000000, 255.000000",
    "BTTTouchBarButtonTextAlignment" : 1,
    "BTTTouchBarItemPlacement" : 1,
    "BTTTouchBarItemIconWidth" : 30,
    "BTTTouchBarButtonCornerRadius" : 6,
    "BTTTouchBarScriptUpdateInterval" : 5,
    "BTTTouchBarAlternateBackgroundColor" : "0.000000, 0.000000, 0.000000, 0.000000",
    "BTTTouchBarAppleScriptString" : "try\r\ttell application \"BetterTouchTool\"\r\t\ttry\r\t\t\tset RetrievedVar to get_string_variable \"ESC_Format\"\r\t\tend try\r\tend tell\r\t\r\tif RetrievedVar is \"Edge\" then\r\t\t--return \"esc        \"\r\t\tupdate_trigger \"033E04C4-A3EC-4394-AF1E-D9AE145118B2\" json \"{\\\"BTTTriggerConfig\\\" : {\\\"BTTTouchBarButtonTextAlignment\\\" : 1,\\\"BTTTouchBarAlternateBackgroundColor\\\" : \\\"0.000000, 0.000000, 0.000000, 0.000000\\\",\\\"BTTTouchBarButtonCornerRadius\\\" : 6,\\\"BTTTouchBarApplyCornerRadiusTo\\\" : 2,\\\"BTTTouchBarButtonName\\\" : \\\"esc       \\\",\\\"BTTTouchBarItemPlacement\\\" : 1,\\\"BTTTouchBarButtonColor\\\" : \\\"0.000000, 0.000000, 0.000000, 255.000000\\\",\\\"BTTTouchBarFreeSpaceAfterButton\\\" : 16,\\\"BTTTouchBarItemIconWidth\\\" : 30,\\\"BTTTouchBarItemPadding\\\" : -26,\\\"BTTTouchBarItemIconHeight\\\" : 30}}\"\r\t\treturn\r\t\t\r\telse\r\t\tupdate_trigger \"033E04C4-A3EC-4394-AF1E-D9AE145118B2\" json \"{\\\"BTTTriggerConfig\\\" : {\\\"BTTTouchBarAlternateBackgroundColor\\\" : \\\"0.000000, 0.000000, 0.000000, 0.000000\\\",\\\"BTTTouchBarItemIconHeight\\\" : 10,\\\"BTTTouchBarButtonCornerRadius\\\" : 6,\\\"BTTTouchBarItemPlacement\\\" : 1,\\\"BTTTouchBarButtonName\\\" : \\\"esc\\\",\\\"BTTTouchBarButtonColor\\\" : \\\"59.000000, 59.000000, 59.000000, 255.000000\\\",\\\"BTTTouchBarItemIconWidth\\\" : 10,\\\"BTTTouchBarFreeSpaceAfterButton\\\" : 20,\\\"BTTTouchBarItemPadding\\\" : 20,\\\"BTTHUDText\\\" : \\\"ESC\\\"}}\"\r\t\treturn\r\tend if\r\t\ron error\r\treturn \"esc\"\rend try",
    "BTTTouchBarAppleScriptStringRunOnInit" : true,
    "BTTTouchBarButtonName" : "esc (listens to settings)",
    "BTTTouchBarAppleScriptUsePath" : 0,
    "BTTTouchBarFreeSpaceAfterButton" : 16,
    "BTTTouchBarItemIconHeight" : 30,
    "BTTTouchBarItemPadding" : -26
  }
}

You could probably hardcode the variable at the top to test the rules.

Thanks for the help!

I have not tried whether that solves your issue, but the update_trigger call should be inside a tell application "BetterTouchTool" block.

It's easiest to test this from an outside Apple Script editor:

Ah, that seems to have made something work...

but it's still struggling. Like literally struggling XD:

I got it working to a point, but it's flickering a lot and is very unstable.
I think i can see the styling working in the background, but it's very flickery.

The round corners are also not changing, and it's stalling every other widget from loading, or operating.

Can you try to make separate tell application "BetterTouchTool" statements for each call to BTT? Problem is that BTT will probably block when doing it like this. Separate tell statements for each call may solve this.

Still flickering here...

Also tried deleting the returns.

I think some properties where missing from your config (properties of the JSON are always replaced completely even if they are objects like the BTTTriggerConfig

tell application "BetterTouchTool"
	
	update_trigger "033E04C4-A3EC-4394-AF1E-D9AE145118B2" json "{\"BTTWidgetName\": \"ESCXX\",\"BTTTriggerConfig\" : { \"BTTScriptType\" : 0, \"BTTTouchBarApplyCornerRadiusTo\" : 2, \"BTTTouchBarButtonColor\" : \"0.000000, 0.000000, 0.000000, 255.000000\", \"BTTTouchBarButtonTextAlignment\" : 1, \"BTTTouchBarItemPlacement\" : 1, \"BTTTouchBarItemIconWidth\" : 30, \"BTTTouchBarButtonCornerRadius\" : 0, \"BTTTouchBarFontColor\" : \"255.000000, 255.000000, 255.000000, 255.000000\", \"BTTTouchBarAlternateBackgroundColor\" : \"0.000000, 0.000000, 0.000000, 0.000000\", \"BTTTouchBarScriptUpdateInterval\" : 5, \"BTTTouchBarAppleScriptString\" : \"\", \"BTTTouchBarAppleScriptStringRunOnInit\" : true, \"BTTTouchBarButtonName\" : \"esc3\", \"BTTTouchBarAppleScriptUsePath\" : 0, \"BTTTouchBarFreeSpaceAfterButton\" : 16, \"BTTTouchBarItemIconHeight\" : 25, \"BTTTouchBarItemPadding\" : 0, \"BTTTouchBarFontColorAlternate\" : \"228.785906, 228.785906, 228.785906, 255.000000\", \"BTTHUDText\" : \"ESC\" }}"
end tell

However update_trigger based on preferences should not be run in intervals, it would be better to only trigger that when the settings actually change. Then you also won't need a script widget for the esc button itself.

//edit: ah that's actually not true anymore, I implemented merging at some point :smiley:
So something like this will also work:

tell application "BetterTouchTool"
	
	update_trigger "033E04C4-A3EC-4394-AF1E-D9AE145118B2" json "{\"BTTWidgetName\": \"ESCXX\",\"BTTTriggerConfig\" : { \"BTTTouchBarButtonColor\" : \"200.000000, 0.000000, 0.000000, 255.000000\" }}"
end tell

1 Like

So here is a slightly edited version that seems to work fine here, however I would strongly recommend to not run the updating logic in the widget itself but from where you do the actual settings:

{
  "BTTWidgetName" : "esc (listens to settings)",
  "BTTTriggerType" : 639,
  "BTTTriggerTypeDescription" : "Apple Script Widget",
  "BTTTriggerClass" : "BTTTriggerTypeTouchBar",
  "BTTPredefinedActionType" : 5,
  "BTTPredefinedActionName" : "Mission Control",
  "BTTEnabled2" : 1,
  "BTTUUID" : "033E04C4-A3EC-4394-AF1E-D9AE145118B2",
  "BTTEnabled" : 1,
  "BTTOrder" : 0,
  "BTTDisplayOrder" : -1,
  "BTTTriggerConfig" : {
    "BTTScriptType" : 0,
    "BTTTouchBarApplyCornerRadiusTo" : 2,
    "BTTTouchBarButtonColor" : "59.000000, 59.000000, 59.000000, 255.000000",
    "BTTTouchBarButtonTextAlignment" : 1,
    "BTTTouchBarItemPlacement" : 1,
    "BTTTouchBarItemIconWidth" : 10,
    "BTTTouchBarButtonCornerRadius" : 0,
    "BTTTouchBarScriptUpdateInterval" : 5,
    "BTTTouchBarAlternateBackgroundColor" : "0.000000, 0.000000, 0.000000, 0.000000",
    "BTTTouchBarAppleScriptString" : "try\r\ttell application \"BetterTouchTool\"\r\t\ttry\r\t\t\tset RetrievedVar to get_string_variable \"ESC_Format\"\r\t\tend try\r\tend tell\r\t\r\tif RetrievedVar is \"Edge\" then\r\t\t--return \"esc        \"\r\t\ttell application \"BetterTouchTool\"\r\t\t\t\r\t\t\tupdate_trigger \"033E04C4-A3EC-4394-AF1E-D9AE145118B2\" json \"{\\\"BTTTriggerConfig\\\" : {\\\"BTTTouchBarButtonTextAlignment\\\" : 1,\\\"BTTTouchBarAlternateBackgroundColor\\\" : \\\"0.000000, 0.000000, 0.000000, 0.000000\\\",\\\"BTTTouchBarButtonCornerRadius\\\" : 6,\\\"BTTTouchBarApplyCornerRadiusTo\\\" : 2,\\\"BTTTouchBarButtonName\\\" : \\\"esc       \\\",\\\"BTTTouchBarItemPlacement\\\" : 1,\\\"BTTTouchBarButtonColor\\\" : \\\"0.000000, 0.000000, 0.000000, 255.000000\\\",\\\"BTTTouchBarFreeSpaceAfterButton\\\" : 16,\\\"BTTTouchBarItemIconWidth\\\" : 30,\\\"BTTTouchBarItemPadding\\\" : -26,\\\"BTTTouchBarItemIconHeight\\\" : 30}}\"\r\t\tend tell\r\t\treturn \"xx1\"\r\t\t\r\telse\r\t\ttell application \"BetterTouchTool\"\r\t\t\t\r\t\t\tupdate_trigger \"033E04C4-A3EC-4394-AF1E-D9AE145118B2\" json \"{\\\"BTTTriggerConfig\\\" : {\\\"BTTTouchBarAlternateBackgroundColor\\\" : \\\"0.000000, 0.000000, 0.000000, 0.000000\\\",\\\"BTTTouchBarItemIconHeight\\\" : 10,\\\"BTTTouchBarButtonCornerRadius\\\" : 0,\\\"BTTTouchBarItemPlacement\\\" : 1,\\\"BTTTouchBarButtonName\\\" : \\\"esc\\\",\\\"BTTTouchBarButtonColor\\\" : \\\"59.000000, 59.000000, 59.000000, 255.000000\\\",\\\"BTTTouchBarItemIconWidth\\\" : 10,\\\"BTTTouchBarFreeSpaceAfterButton\\\" : 20,\\\"BTTTouchBarItemPadding\\\" : 20,\\\"BTTHUDText\\\" : \\\"ESC\\\"}}\"\r\t\tend tell\r\t\treturn \"xx2\"\r\tend if\r\t\ron error\r\treturn \"esc\"\rend try",
    "BTTTouchBarAppleScriptStringRunOnInit" : false,
    "BTTTouchBarButtonName" : "esc (listens to settings)",
    "BTTTouchBarAppleScriptUsePath" : 0,
    "BTTTouchBarFreeSpaceAfterButton" : 20,
    "BTTTouchBarItemIconHeight" : 10,
    "BTTTouchBarItemPadding" : 20,
    "BTTHUDText" : "ESC"
  }
}

If you want to keep it in this widget, make sure to disable "Always run when widget becomes visible". That's because "update_trigger" will basically replace the old widget, insert the new one and display it. If that option is checked it would lead to an infinite loop.

Thanks a lot, I’ll check it out soon.

The main reson for this change is to make copying/pasting easier on my side, since i’d need to paste it into some 50+ different groups so that they all have the same escape key. (CA groups don’t merge into trigger groups). Thus because of this, the setting changing trigger would need to have 50+ UUIDs in it and switch every single one.

I’d appreciate if you could implement this request, which would allow the specific trigger to display everywhere (with an option to exclude certain groups). If that happened I would only need to update one trigger that shows everywhere, instead of 50 triggers that are everywhere.

Thanks for your time! I guess I’ll try that one out and use it as induvidually updating while you work on the new UI / new show on all feature if you approve of it

I'll think about this, it's relatively complicated because it would mix various things in BTT.

Maybe I could add an option to Touch Bar triggers "Merge With Currently Open Groups" and add an additional activation condition to the CAs, something like "currently open touchbar group"

1 Like

Yeah, I guess that could work. I do use CAs to display my persistent triggers (almost)everywhere so I guess the CA condition idea would work.

The merge with currently open trig groups may work but wouldn’t work well unless you could make some kind of exclusion system, which would then be pretty much my initial idea.

Just like to emphasise that a way to exclude certain groups is quite important here. e.g. when you tap one of the four options in my AQT control strip (I’m assuming you know what that is) the button that just became highlighted as white is a completley different trigger. You wouldn’t want the ‘off’ trigger to remain there.

Anyway tldr thanks for considering! Maybe the CA conditions could simplify it a bit for you.

I would probably set it up like

if none are true
opened group is CSplay
opened group is CScal
opened group is CScrtl
opened group is CSapps
...etc for every group that I don’t want it’s contents added into

Jup, I think basing it on an activation group condition would be the only realistic way to integrate it into BTT.
As it's possible to create sub conditions, this should work.

question though,

how would you set it to open on all groups with exceptions instead of all groups that are listed?
if you know what I mean

(basically, will it default to show inside all groups

if not, how would you specify to display in all groups?)

That's already what I'm doing in my screenshot. By setting "none" of the following are true, the activation group would not activate for any of these groups, but for all others.

The topmost "any" would need to change to "All" in this example.

so the new CA behaviour will default to show in all groups unless specified group rules are not met?

Yes just like it does at the moment.

The difference is that you would enable the "Also show in active group" or "Merge with active group" (or however I will name it) in the Touch Bar triggers that are configured in this activation group.

sorry but let me try rephrase that to my understanding. I just want to make sure this concept works logically

To get a trigger to show on all groups with some excepted groups, you do:

  • Put it in the CA group with the new rules

  • Enable the “apply CA group rules” (basically, right?) in the trigger

  • The trigger will then be aware of the CA group rules and show itself within groups.

Other triggers that don’t have this checked will behave as of now - not showing in any trigger groups

No not exactly.

There will be two new things that are separate from each other and can also be used separately:

1.) A new condition in CA groups that looks at the active group name
2.) A new option in the Touch Bar trigger configuration that will allow triggers be merged into the active group, even if they are not part of that group

Feature #1. could also be used for other things, for example maybe you only want certain keyboard shortcuts to work while a specific Touch Bar group is open.

Feature #2. could also be used separately from activation groups, e.g. if you have configured a Touch Bar for a specific app and have a certain button that you want to show inside and outside of every group.

So the triggers will not be aware of the CA group settings at all but if a CA group is activated, and thereby the triggers it contains are loaded, it will show them in the active group - if they have that new setting from #2 enabled.

Ah okay, You seem to know what you’re doing.

The main thing I was trying to ask (sorry if it took a long time to get to this)

How will the triggers that are in CAgroups respond to open trigger groups if there are no trigger group settings applied?

Currently, CAgroups don’t merge into open groups. If this stays, then the exclusions won’t work as right now they don’t merge into any groups anyways. if it stays this way, you would need to add every singe group name that you have as an if true.

If you instead defaulted CAgroups to merge into all groups as long as their rules are met, how would it behave?
If you had this behaviour implemented, how would a group with no group rules behave? would it just add it to any and all open groups as long as its other ‘traditional’ rules are met?

You open a touch bar group, then the activation conditions for all activation groups will be evaluated. If they result in "true", it will load the triggers in the true activation groups.
However this doesn't mean they are shown while a touch bar group is active because by default they don't get merged, at first they are just loaded and might be hidden while a touch bar group is open.
Only if the merge option has been activated for the specific touch bar triggers in that activation group, they will be shown while a touch bar group is open.

Something like this:



1 Like

With that explanation I’m understanding it a bit more, but not absolutley, however I do feel that you’ve thought through and got my issue covered though, so I guess I’ll wait untill it’s implemented to give feedback. (like I’ll get it when it comes out)

All my concerns, questions, logic challenges are now smoothed out, sorry if I was a bother :wink: just wanted to help evaluate with you. I’ve gotta thank you for your time! You’ve added so much features to make AQT work better and I’m sure other advanced users would like this change too. Looking forward to the new feature! (don’t mind if you focus on the new UI first though)

1 Like