Find and click on word on the screen using BTT "find/search text on screen and move mouse" action as a subroutine from Keyboard Maestro

I've been struggling to create a subroutine to find and click on a word on the screen using Better Touch Tool (BTT) "find/search text on screen and move mouse" action from Keyboard Maestro.

I hope there is a way to assign the a search word to a variable in KM, evoke BTT action from KM, pick up the variable in BTT, execute it and click on the word found with the mouse and return the control back to KM. Is it doable? How can one transfer variables between KM and BTT? Is there a way to run a specific BTT macro from KM?

I am aware of the MoveMouseToWord macro for KM created by @Airy but find it more difficult to use to achieve the same result.

Is this what you mean?

Great - thanks - this is how I execute KM macros from BTT, I was not aware I can do it in reverse as well.

Do you know how to share a variable in between the two apps? Can I do it via AppleScript as well?

Yes you can do everything with Apple Script (or with the CLI tool that's included in the lates BTT alphas)

For example you could also copy the apple script for the find text action:

tell application "BetterTouchTool"
trigger_action "{
  BTTIsPureAction: 1,
  BTTPredefinedActionType: 426,
  BTTPredefinedActionName: 'Find or Search Text on Screen & Move Mouse',
  BTTGenericActionConfig2: '{\\\"BTTFindImageSearchRegion\\\":0,\\\"BTTFindTextSearchDirection\\\":0,\\\"BTTActionWaitForConditionsInterval\\\":1,\\\"BTTActionWaitForConditionsTimeout\\\":10,\\\"BTTFindTextMatchMode\\\":1,\\\"BTTFindTextContinueActionExecution\\\":0,\\\"BTTFindText\\\":\\\"lallaa\\\",\\\"BTTFindTextRequiredOccurences\\\":0,\\\"BTTFindTextMoveMouseTo\\\":2,\\\"BTTFindTextSearchOn\\\":0}',
}"

end tell

In general I recommend to use named triggers, they are the easiest to call externally:

tell application "BetterTouchTool" to trigger_named "do-something"

To set a variable you can use

tell application "BetterTouchTool" to set_string_variable "variableName" to "variableValue
1 Like

Fantastic, thanks!

What is the correct way to add variable to the Text to search box in BTT action?

putting it in curly braces should work {variableName}

1 Like

OK I am struggling here. What is wrong with this one? I am trying to use "FindWord" variable from KM, and bring it to BTT, assigning its value to ClickWord variable (do I need to do it?). Is there a way to do it in a simpler manner?


you are only telling keyboard maestro, but not transferring the variable to BTT

I don't know the KM interfaces at all, but it should be something like

tell application "Keyboard Maestro Engine"
    set kmValue to getvariable "FindWord"
end tell

tell application "BetterTouchTool"
    set_string_variable "ClickWord" to kmValue
end tell