Floating menu: set menu item text via variable

Hallo Andreas,

I have severals "floating menus" each with 128 buttons and want to set the "menu item text" via a BTT variable....

I know that it can be done by a script, but that would require a dedicated script for each menu item with its own script name...which is quite a lot of work/etc. in my case...

( I am just lazy, ...as I have the 128 menu item strings already and want to avoid to put those into 128 different scripts...)

Suggestion:

If the menu item text could be set with a BTT variable direct - like below would help a lot.

.
.
The needed variables could then easily set via one script (once) and much more easily maintained / changed for example for a translation into different languages...

like so:

tell application "BetterTouchTool"

    set_string_variable "Var_Name_1" to "Menu 1"
    set_string_variable "Var_Name_2" to "Menu 2"
    set_string_variable "Var_Name_3" to "Menu 3"
    set_string_variable "Var_Name_4" to "Menu 4"

end tell

Thx,
Christian


True, 4.475 supports static variables when put in curly braces, but right now they are only refreshed when the menu item is updated.

However what you are describing (one script, multiple items) is also possible like this:

tell application "BetterTouchTool"

	update_menu_item menu_name "TheMenuName" item_name "TheItemName" json "{BTTMenuItemText: 'hallo'}" with persist

	update_menu_item menu_name "TheMenuName2" item_name "TheItemName2" json "{BTTMenuItemText: 'hallo 1'}" with persist
	
	update_menu_item menu_name "TheMenuName3" item_name "TheItemName3" json "{BTTMenuItemText: 'hallo 2'}" with persist
	
end tell

Thanks Andreas,
great! that works fine...(didn't thought of the second possibility...)

and this will enable me to have all my menu text items in the same spot (script). Makes it much much easier to maintain/change such a huge number of buttons.
I will do some testing / timing for setting 128 vars...


one other issue remains for me, maybe you have an idea?

all my button (in sub menus) actions are basically all the same:
search for a given text (which is the same as their menu text).
That is done like this: set first the var "search" and then call a "Named trigger" (which does the actual seach action based on the var "search").

Suggestion:
Is it maybe possible in the standard action (see screen) to set a variable based on another {static_var_1}. If that would be possible as well I could define all search text vars in the same spot (script).
.
.


.
Thx,
Christian

I think I don't understand your use case. Why not directly use static_var_1 in your named trigger?

If you really need to work that way with variables, it's best to do it with the "run real javascript" action (or via apple script):

(async ()=> {

let static_var_1 = await get_string_variable({variable_name:'static_var_1'})

await set_string_variable({variable_name: 'search', to: static_var_1});

returnToBTT("done");
})();

ah yes, the java script way will do the trick ! Brilliant.


my use case/idea is simplified:
Image you have/need 10 menus with each 128 buttons/menu items each...
all the buttons are almost "the same" (layout) but only have a different text and "seach action".

Instead of having to define 10 menus in BTT I want to define only one single "menu template" which work with 128 variables...(for text and "seach action").

Those variables will be each time defined/set (by script) before loading the " menu template", depending of which one of the 10 menu sets the user needs...

and I believe to have 10 different scripts (to define text and "seach action") in a single spot is much better to handle... even adding one extra menu would be 10 times faster to define.
.
.

maybe (probably) it's obvious but I still don't fully understand why you need two variables then. In your example above, why not just change the value o static_var_1, why does it need another variable with the content of static_var_1 ?

sorry that I can not explain it properly...

perhaps I starting explaining from the back end...
e.g. how the search is done:

"Named trigger - Search VST in Browser" - see screen
that needs a variable "search"
and the content of the variable "search" is different for each button pressed (and needs therefore set before the Named trigger is run...)
..

..
Menu item action
the above Named Trigger - Search VST in Browser is the last part of each Menu item action (see screen)

In this screen you see also the Java script which sets the variable "search" based on
variables set before the menu is loaded - ** see screen 4**

This is probably is the point where it gets "funny". :slight_smile:

The Java script is different for each button (search_1 for button 1, search_2 for button 2 etc.) and this ensures that I can set the search variable (from outside the menu itself - see screen 4 below) to the search variable (needed by the Named trigger - see above)

..


..

..
..
Screen 4 below:
This is actually the "starting point": previous main menu is closed, the variables (menu text and searchtext) are set...(note: not complete, just test data) and the menu template is opened...

You see here just two "Named triggers" to open different menus. Both are the same, except for the Apple Script which is different because of the variables (menu text and searchtext).

To get the rest of the "8 menus", I just need copies of those "Named triggers" and adjust the Apple Script accordingly...

A hell of a story...

..