https://github.com/tatsh/jxa-lib
General library for AppleScript (JXA).
https://github.com/tatsh/jxa-lib
applescript jxa macos typescript
Last synced: about 1 month ago
JSON representation
General library for AppleScript (JXA).
- Host: GitHub
- URL: https://github.com/tatsh/jxa-lib
- Owner: Tatsh
- License: mit
- Created: 2018-08-09T19:25:35.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2026-04-24T00:52:16.000Z (about 2 months ago)
- Last Synced: 2026-04-24T02:31:19.831Z (about 2 months ago)
- Topics: applescript, jxa, macos, typescript
- Language: TypeScript
- Homepage: https://tatsh.github.io/jxa-lib/
- Size: 4.94 MB
- Stars: 40
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
- Citation: CITATION.cff
- Codeowners: CODEOWNERS
- Security: SECURITY.md
- Agents: AGENTS.md
Awesome Lists containing this project
README
# Library for JXA
[](https://www.npmjs.com/package/jxa-lib)
[](https://www.npmjs.com/package/jxa-lib)
[](https://github.com/Tatsh/jxa-lib/tags)
[](https://github.com/Tatsh/jxa-lib/blob/master/LICENSE.txt)
[](https://github.com/Tatsh/jxa-lib/compare/v0.1.10...master)
[](https://github.com/Tatsh/jxa-lib/actions/workflows/codeql.yml)
[](https://github.com/Tatsh/jxa-lib/actions/workflows/qa.yml)
[](https://github.com/Tatsh/jxa-lib/actions/workflows/tests.yml)
[](https://coveralls.io/github/Tatsh/jxa-lib?branch=master)
[](https://github.com/dependabot)
[](https://tatsh.github.io/jxa-lib/)
[](https://github.com/Tatsh/jxa-lib/stargazers)
[](https://github.com/pre-commit/pre-commit)
[](https://prettier.io/)
[](https://www.typescriptlang.org/)
[](https://yarnpkg.com/)
[](https://www.npmjs.com/package/eslint)
[](https://www.npmjs.com/package/jest)
[](https://bsky.app/profile/Tatsh.bsky.social)
[](https://buymeacoffee.com/Tatsh)
[](irc://irc.libera.chat/Tatsh)
[](https://hostux.social/@Tatsh)
[](https://www.patreon.com/Tatsh2)
This is a helper library for AppleScript in JavaScript that works on macOS 10.10 and above. To
properly use this, a bundler must be used such as Webpack. It is recommended to install
[`jxa-types`](https://www.npmjs.com/package/jxa-types) as well.
This repository also demonstrates how to write tests mocking the JXA environment. See the `*.test.ts`
files in `src`.
## Example use
```typescript
import { FileManager } from 'jxa-lib';
const fm = new FileManager();
let attr;
try {
attr = fm.attributesOfItem('/some-file');
} catch (e) {
// Instead of having to pass &error (Ref object) like in Objective-C,
// an exception is thrown
console.log('Maybe /some-file does not exist?');
}
// attr type is FileAttributes or undefined, which does not have prefixes removed
if (attr) {
console.log(attr.NSFileGroupOwnerAccountID); // string
console.log(attr.NSFileModificationDate); // Date object
}
```
## Example with C functions
You do not have to use `ObjC.import()` because all modules will do this on their own.
```typescript
import { stdlib, string } from 'jxa-lib';
const size = 32;
const buf = stdlib.malloc(size); // returns Ref
string.memset(buf, 0, size);
for (let i = 0, c = 'a'.charCodeAt(0); i < size; i++, c++) {
buf[i] = c;
}
const asciiC = 'c'.charCodeAt(0);
const asciiD = 'd'.charCodeAt(0);
// memchr() returns Ref or Ref to NULL
const result = string.memchr(buf, asciiC, size);
if (result[0]) {
// this will be asciiC or null/undefined
console.log(result[0] === asciiC); // true
console.log(result[1] === asciiD); // true
// Getting result[30] or above is not defined behaviour
}
stdlib.free(result);
// Do not print the result of the last expression
stdlib.exit(0);
```