iOS automation SDK and playground for Midscene.js
| Instruction | Video |
|---|---|
| Open Apple Music, search for music by Coldplay, and play it. | ios_playground_demo.mov |
- midscene-ios - Core iOS automation SDK
- midscene-ios-playground - Interactive playground for iOS automation
pnpm installThis project requires Python 3 and several Python packages for iOS device automation:
# Install required Python packages
pip3 install flask pyautogui pillow requestsOr run the automated setup script:
cd packages/ios
./setup.shFor automation to work, you need to grant accessibility permissions:
- Open System Preferences → Security & Privacy → Privacy
- Select Accessibility from the left sidebar
- Add your Terminal application to the list
- If using VS Code or other IDEs, add them as well
For screenshot functionality, you also need screen recording permissions:
- In the same Privacy panel, select Screen Recording
- Add your Terminal application and any IDEs you're using
- Restart the applications after granting permissions
pnpm run buildCreate an .env file.
OPENAI_BASE_URL="xxxx"
OPENAI_API_KEY="xxxx"
MIDSCENE_MODEL_NAME="xxxx"Run with npx.
npx midscene-ios-playground- Node.js 18+
- Python 3 with pip
- macOS (required for iOS device mirroring)
- iOS device with screen mirroring support
- System permissions: Accessibility and Screen Recording permissions for your terminal/IDE
- Midscene AI model configuration
pnpm run devpnpm testimport { agentFromPyAutoGUI } from 'midscene-ios';
import 'dotenv/config';
const main = async () => {
// Create agent
const agent = await agentFromPyAutoGUI();
// Use AI-powered automation
await agent.aiAction('tap the home button');
// Extract data
const apps = await agent.aiQuery('string[], get all app names on screen');
console.log('Apps:', apps);
};
main();The iOS Playground provides a web interface for interactive testing:
npx midscene-ios-playgroundThis will:
- Start a local server
- Open your browser to the playground interface
- Allow you to control iOS devices through a web UI
If you encounter permission errors:
-
Verify Accessibility Permissions:
- Check that your terminal/IDE is listed in System Preferences → Security & Privacy → Privacy → Accessibility
- Try removing and re-adding the application
- Restart the application after granting permissions
-
Verify Screen Recording Permissions:
- Check that your terminal/IDE is listed in System Preferences → Security & Privacy → Privacy → Screen Recording
- Screenshots and screen mirroring require these permissions
If Python package installation fails:
# Update pip first
pip3 install --upgrade pip
# Install packages with user flag if needed
pip3 install --user flask pyautogui pillow requests
# On some systems, you might need to use python instead of python3
python -m pip install flask pyautogui pillow requestsIf you see security warnings about Python or terminal access:
- Click "Open Anyway" in System Preferences → Security & Privacy → General
- Or temporarily disable Gatekeeper:
sudo spctl --master-disable(remember to re-enable it later)
If the default port is occupied:
// Use a different port
const agent = await agentFromPyAutoGUI({ serverPort: 1413 });MIT