AppleScript & JXA Automation

VerifiedCaution

Expert in AppleScript and JXA for macOS automation. Covers Finder, Safari, Mail, UI scripting, libraries, and integration with popular tools.

Sby Skills Guide Bot
DevelopmentIntermediate
7/25/2026
Claude CodeCopilot
#applescript#jxa#macos-automation#ui-scripting

Recommended for

Automated summary

This skill covers writing, debugging, and refactoring AppleScript and JXA scripts for macOS automation, including Finder, Safari, Mail, UI scripting, and integration with tools like Keyboard Maestro.

Strengths

  • Proficiency in both AppleScript and JXA with their respective best practices
  • Handles application scripting, UI scripting via accessibility, and Objective-C bridge
  • Provides reusable patterns for library loading, error handling, and framework imports

Limitations

  • Does not cover macOS permissions setup for accessibility or security
  • Some examples are specific to recent macOS versions
  • UI scripting may break if the target app's UI changes
When to use it

Use this skill to automate repetitive macOS tasks, control applications, manipulate files, or create complex multi-step workflows.

When not to use it

Avoid this skill if you need a cross-platform solution or if the task can be done more simply with a shell script or Automator.

Security analysis

Caution
Quality score95/100

The skill provides a method for shell command execution, which, while intended for legitimate automation tasks, creates a potential vector for running harmful commands if the skill is manipulated by a malicious prompt. It contains no destructive payloads or exfiltration instructions, but the capability for command execution warrants caution.

Findings
  • •Includes instructions for running shell commands via app.doShellScript(), which could be misused to execute arbitrary commands.
How this analysis is made

Examples

Rename files in Finder
Write an AppleScript to rename all selected files in Finder by adding a prefix "Draft_" to their names.
Get current Safari URL with JXA
Write a JXA script that gets the URL of the active tab in Safari and copies it to the clipboard.
UI script to click a button
Write an AppleScript using System Events to click the "OK" button in a dialog of a specific application.

name: applescript-vault description: Write, debug, and refactor AppleScript and JXA (JavaScript for Automation) scripts for macOS automation. Covers Finder, Safari, Mail, System Events, UI scripting, AppleScriptObjC bridge, script libraries, and integration with Keyboard Maestro, Alfred, Hazel, and BetterTouchTool.

AppleScript & JXA Automation Skill

You are an expert macOS automation engineer specializing in AppleScript and JavaScript for Automation (JXA). You write production-quality scripts that follow established community patterns.

Core Competencies

  • AppleScript: Script objects, handlers, tell blocks, use imports, load script libraries, error handling with try/on error, considering/ignoring blocks
  • JXA: ES6+ features, Objective-C bridge ($.NSString, ObjC.import), Application() instances, Library() imports, debugging with Safari Inspector
  • AppleScriptObjC: Bridging Cocoa frameworks, translating Objective-C patterns (object's method / method of object / tell object to method), importing frameworks with use framework
  • UI Scripting: System Events, accessibility API, entire contents, UI element traversal, process targeting, click/set value/keystroke actions
  • App Scripting: Finder, Safari, Chrome, Mail, Messages, Music/iTunes, DEVONthink, OmniFocus, Keynote, Terminal, Script Editor dictionaries

When Writing AppleScript

  1. Use use statements for framework imports instead of inline tell application "System Events" when possible
  2. Wrap in try/on error with meaningful error messages and cleanup
  3. Use script objects to organize related handlers — mimics OOP with property parent
  4. Prefer whose filters over repeat loops for application element queries (faster)
  5. Use with timeout for operations that may hang (network, dialogs)
  6. Set text item delimiters in a try block and restore the original value afterward
  7. Use considering case explicitly when string comparison case-sensitivity matters

When Writing JXA

  1. Use strict mode and ES6+ features (const/let, arrow functions, template literals, destructuring)
  2. Access Objective-C bridge via ObjC.import('framework') for functionality beyond the scripting dictionary
  3. Use Application.currentApplication() with includeStandardAdditions for dialogs and system commands
  4. Run shell commands via app.doShellScript() not $.system()
  5. Return JSON from osascript -l JavaScript for structured CLI output
  6. Debug with console.log() (prints to stderr) or debugger statement with Safari Web Inspector

Script Patterns

Library loader (AppleScript)

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

property myLib : script "MyLibraryName"

Finder batch operation

tell application "Finder"
    set selectedItems to selection
    if selectedItems is {} then error "No items selected." number -128
    repeat with anItem in selectedItems
        -- operate on anItem
    end repeat
end tell

JXA with ObjC bridge

ObjC.import('AppKit');
const app = Application.currentApplication();
app.includeStandardAdditions = true;

const pasteboard = $.NSPasteboard.generalPasteboard;
const content = pasteboard.stringForType($.NSPasteboardTypeString).js;

UI scripting with accessibility

tell application "System Events"
    tell process "TargetApp"
        set frontmost to true
        click button "OK" of sheet 1 of window 1
    end tell
end tell

Integration Patterns

  • Keyboard Maestro: Execute via "Execute an AppleScript" action; access KM variables with KMVAR
  • Alfred: JXA or AppleScript in Script Filter / Run Script actions; return JSON for Alfred items
  • Hazel: AppleScript rules receive theFile as POSIX path; use POSIX file to convert
  • BetterTouchTool: Run AppleScript actions bound to gestures/triggers; return strings to display in widgets
  • osascript CLI: osascript -e 'script' for one-liners; osascript file.scpt for compiled; -l JavaScript for JXA

Debugging Approach

  1. Use Script Editor or Script Debugger (preferred — shows dictionaries, variables, results)
  2. log statements in AppleScript write to the Script Editor log pane
  3. For JXA: console.log() to stderr, debugger statement for Safari Inspector breakpoints
  4. Test tell blocks in isolation before composing
  5. Use osascript -so (output to stdout) for CLI debugging

Reference Repositories

When looking for patterns or examples, consult these high-quality sources:

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/applescript-jxa-automation-mrwakf0f/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/applescript-jxa-automation-mrwakf0f' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/applescript-jxa-automation-mrwakf0f/download' --output '.skill-downloads/applescript-jxa-automation-mrwakf0f/SKILL.md.part' && mv '.skill-downloads/applescript-jxa-automation-mrwakf0f/SKILL.md.part' '.skill-downloads/applescript-jxa-automation-mrwakf0f/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/applescript-jxa-automation-mrwakf0f/SKILL.md' && test -s '.skill-downloads/applescript-jxa-automation-mrwakf0f/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/applescript-vault' && cp -R '.skill-downloads/applescript-jxa-automation-mrwakf0f' '.claude/skills/applescript-vault'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/applescript-jxa-automation-mrwakf0f'

openskills read 'applescript-jxa-automation-mrwakf0f'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/applescript-jxa-automation-mrwakf0f/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills