This skill should be used when the user requests Mac automation via AppleScript, including: Mail operations, Reminders/Calendar management, Safari control, Finder operations, system controls (volume, brightness, notifications, app launching), third-party apps (development tools, task management, media players), or mentions "AppleScript" or "automate Mac".
This skill enables control of macOS applications and system functions through AppleScript execution via the osascript command.
Execute AppleScript commands using the Bash tool with osascript:
osascript -e 'AppleScript code here'
For multi-line scripts:
osascript <<'EOF'
tell application "App Name"
-- commands here
end tell
EOF
Many third-party apps support AppleScript. Common categories include development tools (iTerm2, VS Code), task management (OmniFocus, Things), media players (Spotify), browsers (Chrome), and communication tools. To check if an app supports AppleScript, open Script Editor to browse its dictionary, or try basic commands like tell application "AppName" to get name.
Permission Prompts: First-time use of certain apps triggers macOS permission dialogs. Inform user if automation fails due to permissions.
Sensitive Operations: For destructive operations (delete, shutdown), confirm with user before executing.
Privacy-Sensitive Data: When reading emails or calendar events, only display what user explicitly requests.
Common errors and solutions:
"Application not found" → Check app name spelling"Not authorized" → Guide user to System Preferences > Privacy & Security"Can't get..." → Resource doesn't exist, handle gracefully\" for quotes in stringsosascript -e 'display notification "消息内容" with title "标题"'
osascript -e 'tell application "AppName" to activate'
# Get volume
osascript -e 'output volume of (get volume settings)'
# Set volume (0-100)
osascript -e 'set volume output volume 50'
# Mute
osascript -e 'set volume output muted true'
# Get clipboard
osascript -e 'the clipboard'
# Set clipboard
osascript -e 'set the clipboard to "text"'
For detailed AppleScript patterns by application, consult:
references/mail-applescript.md - Email operations: send, read, search, draftsreferences/reminders-applescript.md - Reminder operations: create, list, completereferences/calendar-applescript.md - Calendar operations: events, calendarsreferences/safari-applescript.md - Safari operations: URLs, tabs, JavaScriptreferences/finder-applescript.md - Finder operations: files, foldersreferences/system-applescript.md - System controls: volume, apps, clipboardWorking examples in examples/:
daily-briefing.applescript - Get today's calendar and unread emailsquick-note.applescript - Create reminder from clipboardScripts in scripts/:
run-applescript.sh - Wrapper for safe AppleScript execution| User Request | Action |
|---|---|
| "发送邮件给xxx" | Use Mail to create and send |
| "提醒我明天..." | Create Reminder with due date |
| "添加日历事件" | Create Calendar event |
| "打开xxx网站" | Safari open URL |
| "调低音量" | Set volume lower |
| "显示通知" | Display notification |
| "打开文件夹" | Finder reveal |
If AppleScript fails:
For permission issues, guide user to: System Preferences > Privacy & Security > Automation
When an AppleScript execution fails or produces unexpected results, follow this protocol to improve the skill's reference documentation:
references/ directoryWhen you identify a fixable issue in the reference documentation:
For incorrect examples:
For missing edge cases:
For common pitfalls:
Use the Edit tool to modify reference files:
Edit tool on: references/{app}-applescript.md
- Fix incorrect code examples
- Add warning notes for known issues
- Include error messages and solutions
When updating reference files, maintain:
After significant improvements:
This protocol ensures the skill continuously improves based on real-world usage and errors encountered.