Docs Getting Started
Getting Started
Write your first automation script using the MAS Python SDK. No installation required — everything runs inside Macro Automation Studio.
1 Prerequisites
- Macro Automation Studio — Download the latest version
- An Android emulator — BlueStacks, LDPlayer, or any supported emulator
2 Open the Code Editor
In Macro Automation Studio, navigate to the Code Editor tab. This is a built-in Python IDE with:
Auto-complete for all SDK functions
Auto-connection to active emulator
Direct access to your image library
One-click script execution
Tip: The SDK is pre-loaded in the Code Editor. You don't need to install anything — just
import mas and go. 3 Your First Script
Paste this into the Code Editor and hit Run. It will get your device info, take a screenshot, and read text from the screen.
import mas
from mas import Region
# Get device info — connection is automatic
device = mas.get_device_info()
print(f"Connected to: {device.name}")
# Get screen size
screen = mas.get_screen_size()
print(f"Screen: {screen.width}x{screen.height}")
# Take a screenshot
screenshot = mas.take_screenshot()
print(f"Screenshot: {screenshot.width}x{screenshot.height}")
# Read all text from screen
text = mas.read_text()
print(f"Screen text: {text.text[:100]}")
print("Done! Your first MAS script worked.") 4 Common Patterns
Find & Click an Image
Use your Image Library assets to locate and interact with UI elements.
find_and_click.py
# Image ID 42 = "Play Button" from your Image Library
match = mas.find_object(42)
if match:
mas.click(*match.center)
print("Clicked play button!")
else:
print("Play button not found on screen") Wait for Element & Act
Wait for a screen to load before interacting.
wait_pattern.py
# Wait up to 30 seconds for loading screen to finish
home = mas.wait_for_object(200, timeout_ms=30000)
if home:
print("Home screen loaded!")
mas.click(*home.center)
else:
raise TimeoutError("Home screen did not load") Read Text from Screen Region
Extract text from a specific area using OCR.
read_score.py
from mas import Region
# Read score from the top-right corner
score_region = Region(x1=800, y1=10, x2=1050, y2=60)
result = mas.read_text(region=score_region, text_filter="integerOnly")
if result.text:
score = int(result.text)
print(f"Current score: {score}") 5 Error Handling
The SDK provides specific exceptions so you can handle errors gracefully.
error_handling.py
import mas
try:
match = mas.find_object(123)
if match:
mas.click(*match.center)
except mas.DeviceNotConnectedError:
print("No device connected")
except mas.ImageNotFoundError:
print("Image ID not in your library")
except mas.TimeoutError:
print("Operation timed out")
except mas.RPCError as e:
print(f"Error {e.code}: {e.message}")