| name | macos-automation |
| description | macOS-specific automation: iMessage/SMS messaging and desktop control (screenshots, clicks, keyboard input). |
| version | 1.0.0 |
| author | Hermes Agent |
| license | MIT |
| platforms | ["macos"] |
| metadata | {"hermes":{"tags":["macos","imessage","sms","desktop-control","automation","screenshots","apple"],"category":"apple"}} |
macOS Automation
macOS-specific automation capabilities for messaging and desktop control.
When to Use
- iMessage section: When sending/receiving iMessages or SMS on macOS
- Desktop Control section: When driving the macOS desktop (screenshots, clicks, keyboard input, window management)
1. iMessage / SMS (imsg CLI)
Overview
Send and receive iMessages and SMS via the imsg CLI on macOS. Uses the Messages app backend — requires macOS with Messages configured.
Prerequisites
- macOS with Messages app configured and signed in
- imsg CLI installed:
brew install imsg or build from source
- Permissions: Terminal/iTerm needs Automation permission for Messages app
- System Preferences → Security & Privacy → Privacy → Automation
- Enable "Messages" for your terminal app
Installation
brew install imsg
git clone https://github.com/wdmimsg/imsg.git
cd imsg && make install
Core Commands
Send Messages
imsg send "Hello!" --to user@example.com
imsg send "Hello!" --to +1234567890
imsg send "Group message" --to user1@example.com --to user2@example.com
imsg send "Check this out" --to user@example.com --attach /path/to/image.jpg
imsg send "Message" --group "Family"
Read Messages
imsg list
imsg read --from user@example.com
imsg read --from user@example.com --limit 10
imsg search "keyword"
imsg search "keyword" --after "2026-01-01" --before "2026-01-31"
Conversation Management
imsg conversations
imsg conversations --from user@example.com
imsg mark-read --from user@example.com
imsg delete --from user@example.com --before "2025-01-01"
Critical Rules
- Phone numbers need country code —
+1 for US/Canada, +44 for UK, etc.
- iMessage vs SMS — iMessage uses Apple ID/email, SMS uses phone number
- Permissions required — Automation permission for Messages app must be granted
- Group chats — use
--group "Name" or find the group's chat GUID
- Attachments — use absolute paths, relative paths may fail
Common Pitfalls
- Messages app not signed in: imsg requires active Messages session
- Fix: Open Messages app and sign in with Apple ID
- Automation permission denied: Terminal can't control Messages
- Fix: System Preferences → Security & Privacy → Automation → enable Messages
- Phone number format wrong: Missing country code → delivery fails
- Fix: Always use
+<country code><number> format
- Group chat not found: Name doesn't match exactly
- Fix: Use
imsg conversations to find exact group name or GUID
- Attachment path wrong: Relative paths or non-existent files
- Fix: Use absolute paths, verify file exists
Workflow Patterns
Monitor for New Messages
while true; do
imsg list --unread | while read -r line; do
echo "New message: $line"
done
sleep 5
done
Auto-Reply Bot
imsg list --unread | while read -r from message; do
if [[ "$message" == *"urgent"* ]]; then
imsg send "I'll get back to you soon" --from-me --to "$from"
fi
done
2. Desktop Control (Computer Use)
Overview
Drive the macOS desktop programmatically: take screenshots, click elements, type text, manage windows. Uses native macOS APIs and accessibility features.
Prerequisites
- macOS with Accessibility permissions enabled
- System Preferences → Security & Privacy → Privacy → Accessibility
- Enable Terminal/iTerm (or whatever runs Hermes)
- Screen Recording permission (for screenshots on macOS 10.15+)
- System Preferences → Security & Privacy → Privacy → Screen Recording
Core Capabilities
Screenshots
screencapture -x /tmp/screenshot.png
screencapture -l <window_id> -x /tmp/window.png
screencapture -R 100,100,800,600 -x /tmp/region.png
screencapture -i -x /tmp/selection.png
Mouse Control
osascript -e 'tell application "System Events" to click at {500, 300}'
osascript -e 'tell application "System Events" to double click at {500, 300}'
osascript -e 'tell application "System Events" to control click at {500, 300}'
osascript -e 'tell application "System Events" to move mouse to {500, 300}'
osascript -e 'tell application "System Events" to drag from {100, 100} to {500, 500}'
Keyboard Input
osascript -e 'tell application "System Events" to keystroke "Hello World"'
osascript -e 'tell application "System Events" to key code 36'
osascript -e 'tell application "System Events" to key code 48'
osascript -e 'tell application "System Events" to key code 51'
osascript -e 'tell application "System Events" to keystroke "c" using command down'
osascript -e 'tell application "System Events" to keystroke "v" using command down'
osascript -e 'tell application "System Events" to keystroke "z" using {command down, shift down}'
Window Management
osascript -e 'tell application "System Events" to get name of every window of every process'
osascript -e 'tell application "System Events" to get name of front window of (first process whose frontmost is true)'
osascript -e 'tell application "Safari" to activate'
osascript -e 'tell application "System Events" to tell process "Safari" to set miniaturized of front window to true'
osascript -e 'tell application "System Events" to tell process "Safari" to set size of front window to {1200, 800}'
osascript -e 'tell application "System Events" to tell process "Safari" to set position of front window to {100, 100}'
Application Control
open -a "Safari"
osascript -e 'tell application "Safari" to quit'
killall "Safari"
pgrep -x "Safari" && echo "Running" || echo "Not running"
osascript -e 'tell application "Safari" to version'
Critical Rules
- Accessibility permissions required — System Preferences must grant access
- Screen Recording permissions for screenshots — macOS 10.15+ requires explicit permission
- Coordinates are absolute — (0,0) is top-left of primary display
- Multi-monitor setups — coordinates span across all displays
- App must be frontmost for keyboard input — activate app before typing
- Use
osascript for complex automation — AppleScript is the native automation language
Common Pitfalls
- Accessibility permission denied: Commands fail silently or with permission errors
- Fix: System Preferences → Security & Privacy → Accessibility → enable Terminal
- Screen Recording permission denied: Screenshots are blank or fail
- Fix: System Preferences → Security & Privacy → Screen Recording → enable Terminal
- Wrong coordinates: Clicking in wrong location
- Fix: Use
screencapture to verify screen layout, check display scaling
- App not frontmost: Keyboard input goes to wrong app
- Fix:
tell application "X" to activate before keyboard commands
- AppleScript syntax errors: Quotes, escaping, or syntax issues
- Fix: Test in Script Editor first, use proper escaping for special characters
- Multi-monitor coordinate confusion: Clicks land on wrong display
- Fix: Use
system_profiler SPDisplaysDataType to understand display layout
Workflow Patterns
Screenshot → Analyze → Act
screencapture -x /tmp/screen.png
osascript -e 'tell application "System Events" to click at {500, 300}'
UI Automation Loop
while true; do
screencapture -x /tmp/check.png
if [[ condition_met ]]; then
break
fi
sleep 1
done
Window Layout Setup
osascript -e 'tell application "Safari" to activate'
osascript -e 'tell application "System Events" to tell process "Safari" to set position of front window to {0, 25}'
osascript -e 'tell application "System Events" to tell process "Safari" to set size of front window to {960, 1055}'
osascript -e 'tell application "Terminal" to activate'
osascript -e 'tell application "System Events" to tell process "Terminal" to set position of front window to {960, 25}'
osascript -e 'tell application "System Events" to tell process "Terminal" to set size of front window to {960, 1055}'
Tool Selection Guide
| Task | Tool |
|---|
| Send iMessage/SMS | iMessage (imsg CLI) |
| Read message history | iMessage (imsg CLI) |
| Monitor for new messages | iMessage (imsg CLI) |
| Take screenshots | Desktop Control (screencapture) |
| Click UI elements | Desktop Control (osascript) |
| Type text / keyboard shortcuts | Desktop Control (osascript) |
| Manage windows | Desktop Control (osascript) |
| Launch/quit applications | Desktop Control (open/osascript) |
Common Pitfalls Across Both Tools
- Permissions not granted — both require explicit macOS permissions
- Silent failures — permission errors may not produce visible error messages
- Coordinate system confusion — multi-monitor setups, display scaling
- App state assumptions — verify app is running/frontmost before interacting
- AppleScript escaping — special characters, quotes, backslashes need proper escaping
Verification Checklists
After iMessage Operation
After Desktop Control Operation