Skip to content
Back to skills

Jxa

ASecurity

Reference for writing JXA (JavaScript for Automation) scripts run through `osascript -l JavaScript`. Covers the JavaScriptCore ES5 constraints, `run(argv)`, and the `Application()` bridge.

  • 18 stars
  • 0 votes
  • 0 copies
  • 7 views
  • Added September 2, 2026
developmentjavascriptjava

Security analysis

A100/100

Scanned November 10, 2026

npx -y skills add bendrucker/claude --skill jxa --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Jxa?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Jxa
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/bendrucker-jxa-claude/badge)](https://www.skillsdirectory.com/skills/bendrucker-jxa-claude)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: mac:jxa
disable-model-invocation: true
description: Reference for writing JXA (JavaScript for Automation) scripts run through `osascript -l JavaScript`. Covers the JavaScriptCore ES5 constraints, `run(argv)`, and the `Application()` bridge.
---

# JXA

JavaScript for Automation (JXA) automates macOS apps via the `Application()` bridge. It runs on JavaScriptCore (ES5).

## Language Constraints

- Use `var` (not `let`/`const`)
- Use for-loops (JXA arrays lack `.map()`, `.filter()`, `.forEach()`)
- Return a JSON string from `run()` (not an object)

```javascript
// WRONG: JXA arrays don't have .map()
// var names = app.windows().map(function(w) { return w.name(); });

// CORRECT: use a for-loop
var windows = app.windows();
var names = [];
for (var i = 0; i < windows.length; i++) {
  names.push(windows[i].name());
}
```

## Script Files

Script files define a `function run(argv)` entry point. `osascript` calls it and prints the return value. The function must be named `run`, not `_run`.

```javascript
#!/usr/bin/env osascript -l JavaScript
function run(argv) {
  var finder = Application("Finder");
  var items = finder.desktop.items();
  var names = [];
  for (var i = 0; i < items.length; i++) {
    names.push(items[i].name());
  }
  return JSON.stringify(names);
}
```

## Tips

- Use `properties()` for batch reads instead of individual getters
- Use `.whose()` for filtering when the app supports it (pushes work to the app)
- `Application.currentApplication()` accesses the current app context
- Extract sdef for any app: `sdef /Applications/AppName.app`

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.