The standard workflow for automating System Settings:
1
Open System Settings
agent-native open "System Settings"
See AXEngine.swift:65-119 for the app launching implementation.
2
Snapshot to find elements
agent-native snapshot "System Settings" -i
The -i flag shows only interactive elements (buttons, checkboxes, text fields). This keeps the output focused and manageable.See SnapshotCommand.swift:14-19 for the snapshot flags.
3
Interact using refs
agent-native click @n5
Every element in the snapshot has a ref (like @n5) that you can use for interactions.
4
Re-snapshot after navigation
agent-native snapshot "System Settings" -i
Important: Always re-snapshot after clicking navigation elements. The UI structure changes, and old refs become invalid.
Refs are invalidated when the UI structure changes. Always re-snapshot after navigation actions.
# Get current window titleagent-native get title "System Settings"# Get text from an elementagent-native get text @n42# Get input valueagent-native get value @n15# Check if element is enabledagent-native is enabled @n20
See GetCommand.swift and IsCommand.swift for details.
#!/usr/bin/env bashset -euo pipefail# Open System Settings and navigate to Displaysagent-native open "System Settings"sleep 1# Click Displays in sidebaragent-native snapshot "System Settings" -i > /tmp/snap.txtDISPLAY_REF=$(grep -i "Displays" /tmp/snap.txt | \ grep -o 'ref=n[0-9]*' | sed 's/ref=//' | head -1)agent-native click "@$DISPLAY_REF"sleep 1# Re-snapshot to see Display settingsagent-native snapshot "System Settings" -i > /tmp/display.txt# Find and adjust brightness slider (example)BRIGHTNESS_REF=$(grep -i "Brightness" /tmp/display.txt | \ grep "AXSlider" | grep -o 'ref=n[0-9]*' | sed 's/ref=//' | head -1)if [[ -n "$BRIGHTNESS_REF" ]]; then # Get current value current=$(agent-native get value "@$BRIGHTNESS_REF") echo "Current brightness: $current" # Set new value (0.0 to 1.0) agent-native fill "@$BRIGHTNESS_REF" "0.75" echo "Set brightness to 75%"fi# Find Night Shift checkboxNIGHT_SHIFT_REF=$(grep -i "Night Shift" /tmp/display.txt | \ grep "AXCheckBox" | grep -o 'ref=n[0-9]*' | sed 's/ref=//' | head -1)if [[ -n "$NIGHT_SHIFT_REF" ]]; then agent-native check "@$NIGHT_SHIFT_REF" echo "Enabled Night Shift"fi
#!/usr/bin/env bash# Open System Settingsagent-native open "System Settings"sleep 1# Navigate to General > Aboutagent-native snapshot "System Settings" -i | grep -i "General"# Click General, then About...# Snapshot the About paneagent-native snapshot "System Settings" -i > /tmp/about.txt# Extract informationgrep -i "macOS\|Version\|Chip\|Memory" /tmp/about.txt
You can interact with elements by filter instead of refs:
# Click by titleagent-native click "System Settings" --title "Wi-Fi"# Fill by labelagent-native fill "System Settings" "MyNetwork" --label "Network Name"# Check by role and titleagent-native check "System Settings" --title "FileVault" --role AXCheckBox
This is useful for one-off commands, but refs are more reliable for multi-step workflows.See ElementResolver.swift:6-51 for filter resolution logic.