Starting in Anka 3.2, we’ve introduced a solution for scripting macOS UI user actions. You may ask, “Why would I want to do that?”. Well, often macOS configuration and applications do not have a CLI allowing you to perform certain actions such as toggling options on and off. This varies from app to app and can severely impact the maintainability and automatability of macOS CI/CD/Automation for your team. With Anka Click scripts, you can programmatically target, click, and send keystrokes to your Anka VM’s UI without needing CLI commands or a shell.
Some examples of what you can automate:
- Disabling SIP from Apple Silicon VMs (which requires Recovery Mode).
- Enabling VNC/Remote Management under System Preferences.
- Enabling certain settings only available in the XCode Simulator Menu (Prefer Discrete GPU) to optimize simulator tests.
Let’s take a look at how it works from the Anka CLI:
# Create a VM without SIP disabled already
❯ ANKA_CREATE_SIP=0 anka --debug create -m 6G -c 4 -d 128G -a /Users/m1mini/Downloads/UniversalMac_13.0_22A379_Restore.ipsw 13.0
# Start it in Recovery Mode (2)
❯ ANKA_START_MODE=2 anka start 13.0
# Run disable-sip script against VM booted in Recovery Mode
❯ anka --debug view --click 13.0/disable-sip/disable-sip.click 13.0
# Check if SIP is disabled
❯ anka run 13.0 csrutil status
System Integrity Protection status: disabled.
Now let’s take a look at the disable-sip.click
script:
$utilities_image iVBORw0KGgoAAAANSUhEUgAAADUAAAAWCAYAAAB. . .
$terminal_image iVBORw0KGgoAAAANSUhEUgAAAEYAAAAYCAYAAABHq. . .
$options_image iVBORw0KGgoAAAANSUhEUgAAAGAAA. . .
$next_image iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABze. . .
$english_image iVBORw0KGgoAAAANSUhEUgAAAEwAAAAWCA. . .
$english_image iVBORw0KGgoAAAANSUhEUgAAAFAAAAAVCAYAAADRhGl. . .
$continue_image iVBORw0KGgoAAAANSUhEUgAAAGQAAAAcCAYA. . .
$bash_image iVBORw0KGgoAAAANSUhEUgAAAEIAAAAVCAYAAADy3zi. . .
(options_image) (continue_image)
if english_image, utilities_image
(english_image) (next_image)
end
(utilities_image) (terminal_image)
+bash_image
"csrutil disable\n"
+1s
"y\n"
+1s
"admin\n"
+1s
"shutdown -h now\n"
I’ve shortened some of the contents of the script to make it easier to read. Let’s go step by step through the script:
1. Right at the top, you’ve got variables containing the base64 version of png images that are used for targeting in later parts of the script. These variables can be an integer and also a string, not just a png image.
2. Next, we have a behavioral sequence that targets two image variables and clicks them in order. Clicks are handled with (<variable_name>)
. This will target the center of and click on where the options_image
is found in the VM’s UI, then the continue_image
3. After that, we have an if
statement that, while english_image
is present AND not utilities_image
, will click on another two images in sequence. Said another way: If utilities_image
does not exist, check for english_image
.
4. Following the if
statement, we see more clicks in a sequence with +bash_image
on the next line. This +
will wait for the image to show up before allowing the script to continue. This ensures the terminal has opened before we proceed to the next steps.
5. Once the terminal has been opened it will then type out "csrutil disable\n"
which includes hitting the return button (\n
). There are more waits (+1s
) between the keystrokes, ensuring enough time for it to generate the input prompts for ("y\n"
) and the root password ("admin\n"
), ending the script with a shutdown command.
Hopefully, by now you can see how much these scripts enable you to do to automate and configure your tools. We’re continuing to add new features to make scripting easier so keep an eye on our Slack and website for announcements. In the meantime, get involved by contributing and submitting your own click scripts for others in the community to use at https://github.com/veertuinc/anka-click-scripts.