Ready-to-use Code ExampleSettingDialogImagePickerAsset

Dialog: Image Picker

Uses the ImagePicker component to let the user pick one of the macro images. The chosen image is used with Asset.image(); the match score the user enters is in the 0-1 range (for example 0.85), and FindParam.mScore() clamps values outside it.

Completion, parameter hints and type checking. Installation instructions and downloads are hosted on GitHub.

Copyable Example Code

You can paste this into the code editor; still verify target image, region, color, text, and timing values in your own device flow.

-- Dialog: image picker
-- score: match threshold from 0 to 1 (0.85 = close match)

local cfg = Setting.builder()
cfg:setTitle("Choose images")

cfg:add("primary", ImagePicker("primary", "Main target image"))
cfg:add("fallback", ImagePicker("fallback", "Fallback target image"))
cfg:add("score", EditText("0.85", 1, "Match score (0-1)"))

Setting.setDialog(cfg:build())
Setting.show()

local primary = Setting.get("primary", "")
local fallback = Setting.get("fallback", "")
local score = math.min(math.max(tonumber(Setting.get("score", "0.85")) or 0.85, 0), 1)

if primary == "" then
  toast("No image selected")
  requestStop()
  return
end

local param = FindParam.mScore(score):timeout(5000)

Snap.screenRefresh()
local region = Region()

local match = region:find(Asset.image(primary), param)
if not match and fallback ~= "" then
  match = region:find(Asset.image(fallback), param)
end

if match then
  click(match)
  toast("Image found and tapped")
end

Implementation and Adaptation Notes

  • Before running, replace sample values such as image names, text, colors, coordinates, and file paths with your own macro values.
  • For examples that use Region or coordinates, retest the target area on different resolutions and DPI values.
  • Tune mScore, timeout, and scan rate in a test macro first, then move the verified values into the production macro.