Visual Agent now includes real-time monitoring for iMessage and WeChat notifications. This feature uses macOS Accessibility APIs to capture notifications, extract attachments, process them with external programs, and optionally send responses.
Notification Appears (iMessage/WeChat)
↓
NotificationCenterObserver (Accessibility API)
↓
NotificationParser (Extract sender, message, attachments)
↓
MessageAttachmentWatcher (FSEvents monitors for files)
↓
MessageProcessor (Orchestrates pipeline)
↓
External Program Execution
↓
MessageResponder (Send iMessage reply via AppleScript)
Required for: Notification monitoring
How to grant:
- Open System Settings (or System Preferences on older macOS)
- Navigate to Privacy & Security → Accessibility
- Click the lock icon and authenticate
- Click the + button
- Navigate to
/Users/your username/git/macos-visual-agent/build/DerivedData/Build/Products/Debug/VisualAgent.app - Click Open
- Ensure the checkbox next to Visual Agent is enabled
Note: Visual Agent will automatically request this permission when launched. If denied, notification monitoring will not work.
Required for: Accessing attachment files from Messages and WeChat
How to grant:
- Open System Settings → Privacy & Security → Full Disk Access
- Click the lock and authenticate
- Click +
- Add VisualAgent.app
- Enable the checkbox
Required for: Sending automated iMessage responses
Setup:
The AppleScript file needs to be placed in the Application Scripts directory:
Location: ~/Library/Application Scripts/com.visualagent.VisualAgent/sendMessage.scpt
Script content:
on run {targetBuddy, messageText}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set theBuddy to buddy targetBuddy of targetService
send messageText to theBuddy
end tell
end runTo create the script:
# Create directory
mkdir -p ~/Library/Application\ Scripts/com.visualagent.VisualAgent/
# Create the script file
cat > ~/Library/Application\ Scripts/com.visualagent.VisualAgent/sendMessage.scpt << 'EOF'
on run {targetBuddy, messageText}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set theBuddy to buddy targetBuddy of targetService
send messageText to theBuddy
end tell
end run
EOFNote: The MessageResponder will automatically create this file if it doesn't exist, but you may need to manually create the directory first.
To process attachments with an external program, configure the path in the MessageProcessor:
// In your setup code:
messageProcessor.externalProgramPath = "/path/to/your/processing/program"Your processing program should:
- Accept a
--file <path>argument - Process the file
- Output the result to stdout
- Exit with code 0 on success
Example processing program:
#!/bin/bash
# save as ~/bin/process-attachment.sh
FILE_PATH=$2 # Second argument after --file
# Process the file (example: extract text from image)
tesseract "$FILE_PATH" stdout
# Or: analyze with AI, convert format, etc.Enable automatic responses:
messageProcessor.autoRespondEnabled = trueImportant: Auto-response only works for iMessage. WeChat does not support programmatic message sending.
✅ Supported:
- Real-time notification capture
- Sender identification
- Full message text extraction
- Attachment detection and file access
- Automated responses (requires AppleScript setup)
- Requires existing conversation thread to send responses
- iCloud Messages sync doesn't affect notification capture
✅ Supported:
- Real-time notification capture
- Sender identification
- Attachment detection (if shown in notification)
- Message text may be truncated in notifications
- CANNOT send responses programmatically (no API, TOS violation)
- Database is encrypted (notification monitoring is the only option)
Attachments are automatically copied to:
~/Documents/VisualAgent/Processing/
Files are renamed with the pattern:
{bundle_id}_{timestamp}_{original_name}.{extension}
Examples:
com.apple.iChat_1696435200_image.jpgcom.tencent.xinWeChat_1696435300_document.pdf
- Notification arrives with attachment indicator
- Pending queue tracks expected file (10 second timeout)
- FSEvents monitors filesystem for new files in:
~/Library/Messages/Attachments/(iMessage)~/Library/Containers/com.tencent.xinWeChat/.../(WeChat)
- File matching by bundle ID, timestamp proximity, and filename hint
- Copy to processing directory
- Execute external program with file path
- Optional response (iMessage only) with program output
When message monitoring is active, you'll see:
- 🟢 Green indicator dot in the mini overlay bar
- 📱 Emoji indicator
- Tooltip: "Message monitoring active"
The app tracks all processed messages including:
- Sender information
- Message text
- Attachment file paths
- Processing results
- Response status (sent/failed)
Solutions:
- Verify Accessibility permission is granted
- Check that Messages/WeChat apps are running
- Test by sending yourself a message
- Check Console app for "📱 NotificationCenterObserver" logs
Solutions:
- Verify Full Disk Access permission
- Check file appears in notification (e.g., "📎 Image")
- Increase timeout if files are slow to appear
- Check processing directory for partial matches
Solutions:
- Verify AppleScript exists at correct location
- Check conversation thread exists in Messages.app
- Test script manually:
osascript ~/Library/Application\ Scripts/com.visualagent.VisualAgent/sendMessage.scpt "+1234567890" "Test message"
Solutions:
- Re-grant Accessibility permission
- Restart Visual Agent after granting permissions
- Check System Settings for any blocked requests
- Notifications: Stored in-memory only (not persisted to disk by default)
- Attachments: Copied to local processing directory
- Message history: Stored in app memory (cleared on quit)
- Zero network requests - all processing is local
- No telemetry or analytics
- iMessage sending uses local Messages.app (no direct iCloud access)
| Permission | Required For | Auto-Requested | Manual Setup |
|---|---|---|---|
| Accessibility | Notification monitoring | ✅ Yes | System Settings |
| Full Disk Access | Attachment files | ❌ No | System Settings |
| Application Scripts | iMessage responses | ❌ No | Manual file creation |
- Grant all permissions
- Launch Visual Agent
- Send yourself an iMessage with an image attachment
- Check Console for log messages:
📬 Received notification from: <sender> via iMessage 📎 Has attachment: image 📄 File created: <filename> ✅ Matched attachment: <filename> for <sender> 💾 Copied attachment to: ~/Documents/VisualAgent/Processing/...
- Ensure WeChat is running
- Have someone send you a WeChat message
- Check for notification capture in logs
- Note: WeChat responses are NOT supported
Implement your own processing logic:
messageProcessor.onAttachmentFound = { fileURL, attachment in
print("Processing: \(fileURL.path)")
// Your custom logic here
// - OCR text extraction
// - Image analysis with Vision/CoreML
// - File format conversion
// - Upload to cloud storage
// etc.
}Add custom filtering in NotificationParser:
// Only process messages from specific senders
if !allowedSenders.contains(sender) {
return nil
}Enable database persistence:
// Store message history in DatabaseManager
databaseManager.saveMessage(
sender: notification.sender,
text: notification.messageText,
timestamp: notification.timestamp,
app: notification.bundleID
)- macOS Version: Requires macOS 12.3+ for ScreenCaptureKit (existing requirement)
- Accessibility API Changes: Apple may change notification UI structure in future macOS versions
- WeChat Responses: No programmatic way to send WeChat messages (by design - TOS)
- Notification Truncation: Long messages may be truncated in notifications
- File Timing: Attachment files may take 1-3 seconds to appear after notification
- Persistent message database
- Vector embeddings for semantic search
- LLM integration for smart responses
- Multi-language support (Chinese, etc.)
- Custom notification filters/rules
- Export message history (JSON/CSV)
For issues or questions:
- Check console logs for detailed error messages
- Verify all permissions are granted
- Test with simple cases first (text-only messages)
- Review this documentation for troubleshooting steps
Last Updated: October 2024 Version: 1.0.0 Compatibility: macOS 12.3+