Scripting macOS UI User Actions With Anka Click

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.

Share this post

networking-performancev1
Unlocking Superior macOS VM Network Performance: Introducing Anka's new networking mode for Apple Silicon
Large and complex enterprises using Anka have many different demands, and we have worked to continue to develop innovative technology to meet these demands. Enterprise infrastructure hardware is often on the cutting edge, and they need advanced capabilities...
Read More
gitlab-with-anka
Anka Cloud Gitlab Executor
Veertu’s Anka and the new Anka Cloud Gitlab Executor Veertu’s Anka is a suite of software tools built on the macOS virtualization platform. It enables the execution of single or multi-use macOS virtual machines (VMs) in a manner similar to Docker....
Read More
mac-scan-v1
Real-Time CVE Scanning of your macOS Build Systems
It’s common that an organization’s macOS build system will download thousands, sometimes tens of thousands of third-party dependencies every hour. When building and testing iOS applications, it typically downloads and installs third-party...
Read More
anka-on-silicon-v1
The ONLY Fully Automated Apple Silicon macOS VM Creation Solution
Starting in Anka 3.1 we announced that Anka is now able to fully automate the macOS installation processes, disabling SIP, and enabling VNC — all previously manual steps users had to perform inside o the VM. At the time of writing this article,...
Read More
mac-scan-fullscan-shells-v3
Real-time, continuous scan of file downloads on macOS for security vulnerabilities
Today, we are announcing the Beta availability of the Mac Scan solution. Mac Scan software runs on macOS systems (bare metal, virtual, EC2 Mac) and scans downloads in real time for security vulnerabilities. There are multiple scenarios why you would...
Read More
Screen Shot 2022-10-17 at 10.13
Anka 3.1- Fully automated VM macOS installation & The Behavior-Driven macOS UI Automation Framework
We are very happy to announce the General Availability of Anka 3.1 for Apple Silicon / ARM macs. In this release, we are taking our approach to iOS CI automation one step further by introducing a Behavior-Driven macOS UI Automation Framework in Anka,...
Read More
ankam1v2
Migrating from Anka on Intel to Anka on M1 Mac for iOS CI
In this blog, we will cover the key topics for migrating from Anka on Intel to Anka on M1/M2 Macs. Anka is an IaaC solution from Veertu to set up an agile Container like CI for iOS CI using macOS VMs. Anka for Intel uses Apple’s Hypervisor.Framework virtualization...
Read More
ami-scanner-featured-v2
World's first Security Vulnerability scanner for EC2 Mac AMIs
We are excited to announce the General Availability of the world’s first security vulnerability scanner for EC2 Mac AMIs. EC2 Mac AMI Scan scans Intel and Apple Silicon macOS EC2 AMIs, detects security vulnerabilities in third-party packages, dependencies,...
Read More
esxi-to-anka
It's time to migrate your iOS CI from ESXi Virtual Mac Infrastructure to native macOS Virtualization
When VMWare ESXi started officially supporting Apple macOS Virtualization on Mac hardware in late 2012, it opened the doors for the possibility of iOS development to move to a Linux-like, agile, scalable CI infrastructure. Soon enough, many iOS enterprise...
Read More
anka-scan-feature
Security vulnerability scanning with Anka Scan
We are excited to announce the general availability (GA) of Anka Scan v1.0.0. As development teams increasingly adopt Infrastructure-as-code for development and production, the incident with Log4J in December 2021 highlighted the importance of security...
Read More