Call BTT Functions from the WebView
Triggering Scripting Functions from any BetterTouchTool Web View
The Floating Web View allows you to trigger various scripting functions via JavaScript.
Important Note: When loaded the webview takes a few milliseconds to initialize BTT's scripting infrastructure. This is why you should only call the scripting functions after the BTTInitialized function has been called (or you can use some fixed delay). For more information see webview lifecycle
The available scripting functions are:
- resize_webview
- trigger_named
- update_touch_bar_widget
- update_stream_deck_widget
- trigger_action
- execute_assigned_actions_for_trigger
- refresh_widget
- get_trigger
- get_triggers
- update_trigger (to create or if exists update a trigger)
- add_new_trigger
- delete_trigger
- delete_triggers
- trigger_named
- trigger_named_async_without_response
- cancel_delayed_named_trigger_execution
- get_dock_badge_for
- get_active_touch_bar_group
- is_true_tone_enabled
- get_location
- set_persistent_string_variable
- set_string_variable
- set_persistent_number_variable
- set_number_variable
- get_number_variable
- get_string_variable
- export_preset
- display_notification
- paste_text
- set_clipboard_content
- get-selected-text
Floating Menus:
- update_menu_item
- get_menu_item_value
- set_menu_item_value
- webview_menu_item_load_html_url_js
Note: There are some built-in variables, which can also be quite helpful:
There are two ways to trigger these scripting functions, both are equally powerful:
1.) Using the bttweb:// links
bttweb:// is a custom URL scheme which allows you to trigger scripting functions and retrieve their results, just like any other http call. You can use them in normal a elements <a href="bttweb://trigger_named/?trigger_name=test"></a> or use XMLHTTPRequest or fetch for this.
The general format for bttweb:// links is always bttweb://**scripting_function_name**/?arg1=xxx&arg2=yyy&arg....
Loading bttweb links using fetch with async/await: // a little helper function
async function bttwebRequest(requestPath) {
const response = await fetch(requestPath);
const responseText = await response.text();
return responseText;
}
let result = await bttwebRequest('bttweb://trigger_named/?trigger_name=test');