When you click a button or navigate to a new pane, the UI changes and your old references may no longer be valid. Take a new snapshot to get fresh references:
agent-native snapshot "System Settings" -i
References like @n5 are stored temporarily. After any significant UI change, re-run the snapshot command to get updated references for the new UI state.
Here’s a complete script that opens System Settings, searches for “Wi-Fi”, and clicks the result:
# 1. Open System Settingsagent-native open "System Settings"# 2. Get interactive elementsagent-native snapshot "System Settings" -i# From the snapshot, we identified:# - @n1 is the search field# - @n3 is the Wi-Fi button# 3. Fill the search fieldagent-native fill @n1 "Wi-Fi"# 4. Wait a moment for search resultssleep 0.5# 5. Take a new snapshot (UI has changed)agent-native snapshot "System Settings" -i# 6. Click the Wi-Fi button (assuming it's still @n3)agent-native click @n3
You can interact with elements without taking a snapshot first:
# Click by titleagent-native click "System Settings" --title "Wi-Fi"# Fill by labelagent-native fill "Safari" --label "Address" "https://github.com"# Check by role and titleagent-native check "System Settings" --title "Wi-Fi" --role AXCheckBox
Filter-based interaction is less reliable than snapshot refs because it searches the tree each time. Use snapshot refs for multi-step workflows.
Add this to your AGENTS.md, CLAUDE.md, or similar:
## macOS App AutomationUse `agent-native` for controlling native macOS apps. Run `agent-native --help` for all commands.Core workflow:1. `agent-native open <app>` - Launch the app2. `agent-native snapshot <app> -i` - Get interactive elements with refs3. `agent-native click @n1` / `fill @n2 "text"` - Interact using refs4. Re-snapshot after page/pane changes