midscene-ios-playground
v0.1.9
Published
iOS playground for Midscene
Readme
midscene-ios-playground
iOS playground for Midscene.js - Control iOS devices through natural language commands using screen mirroring.
Quick Start
npx midscene-ios-playgroundThis will:
- Automatically start the PyAutoGUI server on port 1412
- Launch the iOS playground web interface
- Open the playground in your default browser
Prerequisites
macOS System: iOS playground requires macOS (tested on macOS 11 and later).
Python 3 and Dependencies: The playground will automatically manage the PyAutoGUI server, but you need Python 3 with required packages:
pip3 install pyautogui flask flask-corsiPhone Mirroring: Use iPhone Mirroring (macOS Sequoia) to mirror your physical iPhone to your Mac screen.
AI Model Configuration: Set up your AI model credentials. See Midscene documentation for supported models.
Features
- Automatic Server Management: PyAutoGUI server starts and stops automatically
- Auto-Detection: Automatically detects iPhone Mirroring window position and size
- Natural Language Control: Control iOS devices using natural language commands
- Screenshot Capture: Takes screenshots of only the iOS mirrored region
- Coordinate Transformation: Automatically maps iOS coordinates to macOS screen coordinates
- Real-time Interaction: Direct interaction with iOS interface elements through AI
Usage
Start the playground:
npx midscene-ios-playgroundSet up iPhone Mirroring: Open iPhone Mirroring app on your Mac (macOS Sequoia) and connect your iPhone
Configure AI Model: In the playground web interface, configure your AI model credentials
Auto-detect or Manual Setup:
- Click "Auto Detect iOS Mirror" for automatic configuration, or
- Manually set the mirror region coordinates
Use natural language commands to interact with your iOS device:
- Action: "tap the Settings app"
- Query: "extract the battery percentage"
- Assert: "the home screen is visible"
Development
To run the playground in development mode:
cd packages/ios-playground
npm install
npm run dev:serverThis will build the project and start the server locally.
Architecture
The iOS playground architecture consists of:
- Frontend: Web-based interface for AI interaction (built with React/TypeScript)
- Playground Server: Express.js server that bridges between frontend and iOS automation
- PyAutoGUI Server: Python Flask server for screen capture and input control
- iPhone Mirroring: macOS iPhone Mirroring for device display
- Midscene AI Core: AI-powered automation engine with iOS device adapter
- Coordinate Transformation: Automatic mapping between iOS logical coordinates and macOS screen coordinates
How It Works
- Screen Mirroring: iOS device screen is displayed on macOS through iPhone Mirroring
- Auto-Detection: Python server detects the mirroring window position and size using AppleScript
- Coordinate Mapping: iOS logical coordinates (e.g., 200, 400) are automatically transformed to macOS screen coordinates
- AI Processing: Midscene AI analyzes screenshots and determines actions based on natural language commands
- Action Execution: Actions are executed on the macOS screen within the iOS mirrored region
Troubleshooting
PyAutoGUI Server Issues
If the PyAutoGUI server fails to start automatically, check:
# Check if port 1412 is available
lsof -i :1412
# Manually start the server
cd packages/ios
node bin/server.js 1412iPhone Mirroring Detection Issues
- Ensure iPhone Mirroring app is open and visible on screen
- Try clicking "Auto Detect iOS Mirror" in the playground interface
- Manually configure mirror coordinates if auto-detection fails
- Check that the iPhone Mirroring window is not minimized
Permission Issues
On macOS, you may need to grant the following permissions:
- Accessibility: System Preferences > Security & Privacy > Privacy > Accessibility
- Screen Recording: System Preferences > Security & Privacy > Privacy > Screen Recording
Add Terminal, Python, or your development environment to these permission lists.
Python Dependencies
If you encounter Python-related errors:
# Install or upgrade required packages
pip3 install --upgrade pyautogui flask flask-cors
# On macOS, you might need to install using conda or homebrew
brew install [email protected]Mirror Region Configuration
If clicks are not landing in the right place:
- Use the "Auto Detect iOS Mirror" feature first
- If manual configuration is needed, measure the exact position and size of your iPhone Mirroring window
- Account for window borders and title bars when setting coordinates
