Automates macOS apps via Apple Events using AppleScript (discovery), JXA (legacy), and PyXA (modern Python)...
JXA and AppleScript are legacy (last major updates: 2015-2016). Modern alternatives:
Test scripts on target macOS due to:
tell application "Finder" to get name of first item in desktoptry { ... } catch (e) { console.log('Error:', e.message); }try ... on error errMsg ... end tryosascript -e 'tell application "Finder" to get name of home'osascript for CLI or pipeline use.tell application "System Events" to click button 1 of window 1 of process "App"Application('System Events').processes.byName('App').windows[0].buttons[0].click()Application("App").running() returns trueskills/automating-mac-apps/scripts/request_automation_permissions.sh (or .py).skills/automating-<app>/scripts/set_up_<app>_automation.{sh,py} (calendar, notes, mail, keynote, excel, reminders).skills/automating-voice-memos/scripts/set_up_voice_memos_automation.sh to activate app + check data paths; enable Accessibility + consider Full Disk Access.PyXA (Python for macOS Automation) - Preferred for new projects:
app.lists().reminders().title()# Install PyXA
pip install mac-pyxa
# Or with pip3 explicitly
pip3 install mac-pyxa
# Requirements:
# - Python 3.10+ (check with: python3 --version)
# - macOS 12+ (Monterey or later recommended)
# - PyObjC is installed automatically as a dependency
# Verify installation
python3 -c "import PyXA; print(f'PyXA {PyXA.__version__} installed successfully')"
Note: All app-specific skills in this plugin that show PyXA examples assume PyXA is installed. See this section for installation.
import PyXA
# Launch Safari and navigate
safari = PyXA.Safari()
safari.activate()
safari.open_location("https://example.com")
# Get current tab URL
current_url = safari.current_tab.url
print(f"Current URL: {current_url}")
import PyXA
reminders = PyXA.Reminders()
work_list = reminders.lists().by_name("Work")
# Add new reminder
new_reminder = work_list.reminders().push({
"name": "Review PyXA documentation",
"body": "Explore modern macOS automation options"
})
PyXA Official Resources:
PyObjC (Python-Objective-C Bridge) - For Low-Level macOS Integration:
pip install pyobjc
# Installs bridges for major frameworks
from Foundation import NSAppleScript
# Execute AppleScript from Python
script_source = '''
tell application "Safari"
return URL of current tab
end tell
'''
script = NSAppleScript.alloc().initWithSource_(script_source)
result, error = script.executeAndReturnError_(None)
if error:
print(f"Error: {error}")
else:
print(f"Current Safari URL: {result.stringValue()}")
from ScriptingBridge import SBApplication
# Control Mail app
mail = SBApplication.applicationWithBundleIdentifier_("com.apple.Mail")
inbox = mail.inboxes()[0] # Access first inbox
# Get unread message count
unread_count = inbox.unreadCount()
print(f"Unread messages: {unread_count}")
PyObjC Official Resources:
JXA has no updates since 2016. Use PyXA for new projects when possible.
automating-[app] skills as needed)ci-cd-tcc for advanced permission management in automated environmentsmastering-applescript for AppleScript-focused workflowsPermission Management:
Official Apple Security Guidance:
JSON.stringify(result) in JXA.console.log(JSON.stringify({files: files, count: files.length}))osascript exits with 0 for success, non-zero for failure.automating-mac-apps/references/basics.mdautomating-mac-apps/references/applescript-basics.mdautomating-mac-apps/references/recipes.mdautomating-mac-apps/references/cookbook.mdautomating-mac-apps/references/applescript-performance.mdautomating-mac-apps/references/ci-cd-tcc.mdautomating-mac-apps/references/shell-environment.mdautomating-mac-apps/references/ui-scripting-inspector.mdautomating-mac-apps/references/pyxa-core-api-reference.mdautomating-mac-apps/references/pyxa-basics.md (Modern Python automation fundamentals)automating-mac-apps/references/applescript-to-pyxa-conversion.md (Migration guide with examples)automating-mac-apps/references/translation-checklist.md (Comprehensive guide with examples and pitfalls)automating-mac-apps/references/helpers.jswhose Batching Patterns: automating-mac-apps/references/whos-batching.mdautomating-mac-apps/references/dictionary-strategies.mdautomating-mac-apps/references/applescript-asobjc.mdRelated Skills:
web-browser-automation: Complete browser automation guide (Chrome, Edge, Brave, Arc)