How to run javascript function in Floating WebView from Action

I need to trigger the running of a javascript function in a Floating WebView from an arbitrary action (specifically, a Generic Device). Basically, the same as webview_menu_item_load_html_url_js but for Floating WebViews (I prefer not to use Floating Menus as I cannot edit the HTML in an external editor).

I know I could build a hack on top of BTTNotification to have the WebView informed of variable changes, but I suspect that would lose some events (there seems to be no thread-safe way to update variables).

Any ideas?

Thanks so much

currently the notifications would be the only way, but I‘ll update the `webview_menu_item_load_html_url_js to also allow floating webviews.

In theory the Floating Menus should also allow to load local files, but there is currently a bug that prevents this. I’ll fix that later today or tomorrow!

Actually I realized this was already working. You can execute Java Script in a standard Floating WebView, accessing it via its trigger's UUID:

tell application "BetterTouchTool"
	webview_menu_item_load_html_url_js "9E0859EA-8C08-4A5F-94BE-27D56269FD28" javascript_to_execute "alert('hello')"
end tell

4.185 now adds the possibility to use localfile:// and presetfile:// in the floating menu webview's to access local files.

1 Like