Overview
Ensures a checkbox or switch is in the checked state. If already checked, does nothing. This is an idempotent operation, safe to call multiple times.Syntax
Parameters
Element reference from snapshot (must be a
checkbox or switch)Response
Response Fields
The action performed (
check)The element reference that was checked
Element state after operation
role(string): “checkbox” or “switch”value(string): “1” (checked)states(string[]): Includes “checked”
AX-First Strategy
The check command:- Reads current state via
kAXValueAttribute - If already checked (value = 1), returns success without action
- If unchecked (value = 0), performs
kAXPressAction - Verifies final state is checked
Usage Examples
Check Checkbox
Idempotent Check
Enable Multiple Options
Conditional Check
Check vs Toggle
| Command | Behavior | Idempotent | Use Case |
|---|---|---|---|
check | Ensure checked | Yes | Desired end state |
toggle | Flip state | No | Unknown current state |
uncheck | Ensure unchecked | Yes | Desired end state |
check when:
- You need the checkbox checked
- Idempotency is important
- Running automation scripts repeatedly
- Setting up known state
toggle when:
- You want to flip whatever the current state is
- Simulating user clicking
Supported Element Types
| Role | Check Behavior |
|---|---|
checkbox | Sets to checked |
switch | Sets to on |
radiobutton | Selects option |
State Verification
Error Cases
| Error Code | Cause | Recovery |
|---|---|---|
ELEMENT_NOT_FOUND | Ref doesn’t exist in current refmap | Run snapshot to refresh |
STALE_REF | Element no longer matches saved ref | Run snapshot and use new ref |
ACTION_FAILED | Cannot set checked state | Element may be disabled |
ACTION_NOT_SUPPORTED | Element is not a checkbox/switch | Wrong element type |
Common Use Cases
- Configuration: Enable settings in preferences
- Forms: Pre-fill form checkboxes
- Permissions: Grant permissions
- Feature Flags: Enable features
- Setup Scripts: Configure applications
Idempotency Benefits
Notes
- Check is idempotent; safe to call when already checked
- Returns success immediately if already in checked state
- Pair with
uncheckfor state management - Use
is @ref checkedto verify state before or after - For radio buttons,
checkselects the option - Some apps may trigger onChange events even on no-op check
- Always verify critical state changes with
iscommand