### Run Example Commands Source: https://github.com/jxa-userland/jxa/blob/master/example/README.md These commands outline the steps to set up and run the JXA examples using Yarn and Node.js. Ensure dependencies are installed before execution. ```shell yarn yarn run build node lib/cli.js ``` -------------------------------- ### Start @jxa/repl Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/repl/README.md Launch the JXA REPL after global installation. You can then execute JXA commands directly. ```bash jxa-repl ``` -------------------------------- ### Example JXA REPL Command Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/repl/README.md An example of a JXA command that can be executed within the REPL to get the current user's name. ```javascript Application("System Events").currentUser().name(); ``` -------------------------------- ### Install Dependencies and Bootstrap Monorepo Source: https://github.com/jxa-userland/jxa/blob/master/CONTRIBUTING.md Run these commands to install project dependencies and set up the monorepo for development. ```shell yarn install yarn run bootstrap ``` -------------------------------- ### Install Dev Dependencies and Run Tests Source: https://github.com/jxa-userland/jxa/blob/master/example/README.md This command installs development dependencies and executes the project's tests using npm. It's a standard procedure for verifying code integrity. ```shell npm i -d && npm test ``` -------------------------------- ### Install @jxa/repl Globally Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/repl/README.md Install the @jxa/repl package globally using npm. This makes the `jxa-repl` command available system-wide. ```bash npm install -g @jxa/repl ``` -------------------------------- ### Start Interactive JXA REPL with @jxa/repl Source: https://context7.com/jxa-userland/jxa/llms.txt Starts an interactive Node.js REPL where each line is evaluated as JXA code via osascript. Previous commands accumulate in the session buffer, allowing variables to remain accessible. Use `.clear` to reset the buffer. ```bash # Run interactively with npx npx @jxa/repl # Or install globally npm install -g @jxa/repl jxa-repl # Session example: # > var sys = Application("System Events"); # > sys.currentUser().name(); # 'jdoe' # > var finder = Application("Finder"); # > finder.windows.length; # 3 # > .clear ← resets buffer, all variables are released # > ``` ```typescript // Use JXARepl programmatically in Node.js import { JXARepl } from "@jxa/repl/src/repl"; const repl = new JXARepl(); repl.start(); // starts the interactive REPL session // To stop programmatically: // repl.stop(); ``` -------------------------------- ### Executing JXA Code to Get System Information Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/run/README.md An example of running JXA code to interact with macOS system events, specifically retrieving the current user's name. The result is compared against the environment variable. ```ts (async () => { const result = await run( // run this function as JXA code () => { return Application("System Events") .currentUser() .name() } ); assert.strictEqual(result, process.env.USER); })(); ``` -------------------------------- ### Run @jxa/repl with npx Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/repl/README.md Execute the @jxa/repl tool without global installation using npx. This is useful for trying out the tool or for projects with specific version requirements. ```bash npx @jxa/repl ``` -------------------------------- ### Get Safari Version and Current User Name with JXA Source: https://github.com/jxa-userland/jxa/blob/master/example/README.md These functions execute JXA code to retrieve the Safari version and the current macOS user's name. They require importing `@jxa/global-type` and `@jxa/run`. The `example` function demonstrates how to use these JXA functions within a Node.js environment. ```typescript import "@jxa/global-type"; import { run } from "@jxa/run"; /** * get safari version * This function execute JXA code */ export const safariVersion = () => { return run(() => { const Safari = Application("Safari"); return Safari.version(); }); }; /** * get current mac system user * This function execute JXA code */ export const currentUserName = () => { return run(() => { const sys = Application("System Events"); return sys.currentUser().name(); }); }; // This main is just a Node.js code export const example = async () => { const version = await safariVersion(); const userName = await currentUserName(); return `User: ${userName}, Safari: ${version}`; }; ``` -------------------------------- ### `@jxa/repl` — Interactive JXA REPL Source: https://context7.com/jxa-userland/jxa/llms.txt The `@jxa/repl` package starts an interactive Node.js REPL where each line of input is evaluated as JXA code via `osascript`. Previous commands accumulate in the session buffer, so variables defined in earlier lines remain accessible. The `.clear` command resets the buffer. ```APIDOC ## `@jxa/repl` ### Description Starts an interactive Node.js REPL where each line of input is evaluated as JXA code via `osascript`. Previous commands accumulate in the session buffer, so variables defined in earlier lines remain accessible. The `.clear` command resets the buffer. ### Usage Run interactively with npx: ```bash npx @jxa/repl ``` Or install globally: ```bash npm install -g @jxa/repl jxa-repl ``` ### Programmatic Usage Use JXARepl programmatically in Node.js: ```typescript import { JXARepl } from "@jxa/repl/src/repl"; const repl = new JXARepl(); repl.start(); // starts the interactive REPL session // To stop programmatically: // repl.stop(); ``` ### Session Example ```bash # > var sys = Application("System Events"); # > sys.currentUser().name(); # 'jdoe' # > var finder = Application("Finder"); # > finder.windows.length; # 3 # > .clear ← resets buffer, all variables are released # > ``` ``` -------------------------------- ### CLI: Convert App to TypeScript Definitions with @jxa/sdef-to-dts Source: https://context7.com/jxa-userland/jxa/llms.txt Install and use the @jxa/sdef-to-dts CLI tool to convert an application's Apple Scripting Definition (.app bundle) into a TypeScript declaration file (.d.ts). Useful for applications not covered by @jxa/types. ```bash # Install globally npm install -g @jxa/sdef-to-dts # Convert Safari.app to a TypeScript declaration file npx @jxa/sdef-to-dts /Applications/Safari.app --output ./safari.d.ts # Convert to a directory (file is named after the app) npx @jxa/sdef-to-dts /Applications/TextEdit.app --output ./types/ # Show help npx @jxa/sdef-to-dts --help # Output: # Scripting definition files (sdefs) to TypeScript (d.ts) # Usage # $ npx @jxa/sdef-to-dts --output # Options # --output, -o path to an Application.d.ts or a directory to write to ``` -------------------------------- ### Typed Application() Function with @jxa/types Source: https://context7.com/jxa-userland/jxa/llms.txt Use the typed Application() factory to get fully-typed objects for built-in macOS applications. Supports custom application types via generics. Ensure @jxa/types is installed. ```typescript import { Application } from "@jxa/types"; // Built-in application — fully typed const safari = Application("Safari"); const url: string = safari.windows[0].currentTab.url(); // typed const docName: string = safari.documents[0].name(); // typed // System Events — typed User interface const sys = Application("System Events"); const fullName: string = sys.currentUser().fullName(); const homePath = sys.currentUser().homeDirectory(); // Finder — typed item access const finder = Application("Finder"); finder.includeStandardAdditions = true; const selection = [].slice.call(finder.selection()); finder.displayAlert(selection.length.toString()); // Custom application type via generics interface GoogleChrome { windows: Array<{ activeTab: { url(): string } }>; } const chrome = Application("Google Chrome"); const tabUrl = chrome.windows[0].activeTab.url(); // Application lifecycle methods (available on all apps) const mail = Application("Mail"); if (!mail.running()) { mail.launch(); mail.activate(); } mail.quit(); ``` -------------------------------- ### ObjectSpecifier Namespace for Runtime Introspection Source: https://context7.com/jxa-userland/jxa/llms.txt Use the ObjectSpecifier namespace to check if an object is a JXA ObjectSpecifier and to get the class name of JXA objects. Requires importing @jxa/global-type and using the @jxa/run utility. ```typescript import "@jxa/global-type"; import { run } from "@jxa/run"; await run(() => { const finder = Application("Finder"); const desktop = finder.desktop; // Check if an object is a JXA ObjectSpecifier const isSpec: boolean = ObjectSpecifier.hasInstance(desktop); // true const isPlain: boolean = ObjectSpecifier.hasInstance("hello"); // false // Get the class name of a JXA object const className: string = ObjectSpecifier.classOf(desktop); // "desktop-object" Automation.log(className); }); ``` -------------------------------- ### Convert application bundles to d.ts using the command line Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/sdef-to-dts/README.md Execute this command to convert an application bundle (e.g., an .app file) into a TypeScript definition file (.d.ts). Specify the input application path and the desired output file or directory. ```bash npx @jxa/sdef-to-dts /Applications/Safari.app --output ./safari.d.ts ``` -------------------------------- ### Basic Usage of run() Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/run/README.md Illustrates the basic structure for calling the `run` function with a JXA function and its arguments. The JXA function is serialized and executed in a separate environment. ```js const resultPromise = run(JSXFn, argumentsOfJSXFn); ``` -------------------------------- ### run(jxaCodeFunction: (...args: any[]) => void, ...args: any[]): Promise Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/run/README.md Executes a given JXA function and returns a Promise that resolves with the result. The JXA function is serialized and executed in a separate environment. Arguments must be passed explicitly. ```APIDOC ## run(jxaCodeFunction: (...args: any[]) => void, ...args: any[]): Promise ### Description This function executes the provided `jxaCodeFunction` within a JXA environment and returns a Promise that resolves with the function's return value. The `jxaCodeFunction` is serialized to a string before execution, meaning it cannot access variables from its parent scope. Any arguments required by `jxaCodeFunction` must be passed explicitly as `args`. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Method Asynchronous function call ### Endpoint N/A (Function call) ### Request Example ```javascript const resultPromise = run(JSXFn, argumentsOfJSXFn); ``` ### Response #### Success Response - **R** (Promise) - A Promise that resolves with the return value of the `jxaCodeFunction`. #### Response Example ```javascript (async () => { const result = await run(name => { return "Hello there, " + name + "!"; }, "nodejs"); // result will be "Hello there, nodejs!" })(); ``` ### Warning - The `jxaCodeFunction` cannot close over variables in a parent's scope due to serialization. - Arguments must be passed explicitly using the `...args` parameter. ``` -------------------------------- ### Run All Package Tests Source: https://github.com/jxa-userland/jxa/blob/master/CONTRIBUTING.md Execute this command to run all tests across all packages in the monorepo. ```shell yarn test ``` -------------------------------- ### Run JXA from Node.js with @jxa/run Source: https://github.com/jxa-userland/jxa/blob/master/README.md Use the '@jxa/run' package to execute JXA code from a Node.js environment. The provided callback function is executed as JXA. ```typescript import "@jxa/global-type"; import { run } from "@jxa/run"; export const currentUserName = () => { // This callback function is run as JXA return run(() => { const sys = Application("System Events"); return sys.currentUser().name(); }); }; // Main code is Node.js export const example = async () => { const userName = await currentUserName(); return `User: ${userName}`; }; ``` -------------------------------- ### Release Flow Commands Source: https://github.com/jxa-userland/jxa/blob/master/CONTRIBUTING.md Commands to version up and release packages. These are typically run after updating package versions. ```shell npm run versionup npm run release ``` -------------------------------- ### Convert sdef files to d.ts using the library Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/sdef-to-dts/README.md Use this snippet to programmatically convert .sdef files from an input directory to .d.ts files in an output directory. Ensure the input and output directories are correctly configured. ```typescript const fs = require("fs"); const path = require("path"); const { transform } = require("@jxa/sdef-to-dts"); const sdefDir = path.join(__dirname, "./input"); const outputDir = path.join(__dirname, "./output"); const promises = fs.readdirSync(sdefDir).map(async caseName => { const fileName = path.basename(caseName, ".sdef"); const normalizedTestName = fileName.replace(/\s/g, ""); const actualContent = fs.readFileSync(path.join(fixturesDir, caseName), "utf-8"); console.log("transform " + normalizedTestName); const actual = await transform(normalizedTestName, actualContent); fs.writeFileSync(path.join(outputDir, normalizedTestName) + ".d.ts", actual, "utf-8"); }); Promise.all(promises).then(() => { console.log("All write"); }); ``` -------------------------------- ### Use Custom Application Type with Generics Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/types/README.md Demonstrates how to use generics with the `Application` type to specify a custom application interface, such as `GoogleChrome`. This allows for type-safe access to application-specific properties and methods. ```typescript import { Application } from "@jxa/types"; import { GoogleChrome } from "./fixtures/GoogleChrome"; // Pass Custom Application type as generics const chrome = Application("Google Chrome"); const frontWindow: GoogleChrome.Window = chrome.app.windows[0]; ``` -------------------------------- ### `@jxa/run` — `run(fn, ...args): Promise` Source: https://context7.com/jxa-userland/jxa/llms.txt Serializes a JavaScript function, sends it to macOS `osascript -l JavaScript`, and resolves a Promise with the return value. The function passed to `run` is stringified and executed in an isolated JXA environment; it cannot close over variables from Node.js scope. All data must be passed explicitly as arguments after the function. ```APIDOC ## `@jxa/run` — `run(fn, ...args): Promise` ### Description Serializes a JavaScript function, sends it to macOS `osascript -l JavaScript`, and resolves a Promise with the return value. The function passed to `run` is stringified and executed in an isolated JXA environment — it **cannot** close over variables from Node.js scope; all data must be passed explicitly as arguments after the function. ### Usage Examples 1. **No arguments — get the current logged-in username** ```ts import "@jxa/global-type"; import { run } from "@jxa/run"; const currentUserName = (): Promise => run(() => { return Application("System Events").currentUser().name(); }); // Example usage: (async () => { const user = await currentUserName(); console.log(user); // => "jdoe" })(); ``` 2. **Pass arguments explicitly — greet by name** ```ts import "@jxa/global-type"; import { run } from "@jxa/run"; const greet = (name: string): Promise => run((name) => { return "Hello, " + name + "!"; }, name); // Example usage: (async () => { const msg = await greet("macOS"); console.log(msg); // => "Hello, macOS!" })(); ``` 3. **Multi-argument — set a Finder label on a path** ```ts import "@jxa/global-type"; import { run } from "@jxa/run"; const setLabel = (filePath: string, labelIndex: number): Promise => run((filePath, labelIndex) => { const finder = Application("Finder"); finder.items.byName(filePath).labelIndex = labelIndex; }, filePath, labelIndex); // Example usage: (async () => { await setLabel("/Users/jdoe/Documents/report.txt", 3); })(); ``` 4. **Executing arbitrary JXA code** ```ts import "@jxa/global-type"; import { run } from "@jxa/run"; (async () => { const version = await run(() => Application("Safari").version()); console.log(version); // => "17.4.1" })(); ``` ``` -------------------------------- ### Passing Arguments to JXA Function Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/run/README.md Demonstrates how to correctly pass arguments to the JXA function. The function must explicitly receive arguments; it cannot access variables from the parent scope. ```ts // OK (async () => { // `name` is "nodejs" const result = await run(name => { return "Hello there, " + name + "!" }, "nodejs"); assert.strictEqual(result, "Hello there, nodejs!"); })(); ``` ```ts // NG (async () => { const name = "nodejs" const result = await run(name => { return "Hello there, " + name + "!"; // can not access to `name` from JXA enviroment }); assert.strictEqual(result, "Hello there, nodejs!"); })(); ``` -------------------------------- ### `@jxa/run` — `runJXACode(code: string): Promise` Source: https://context7.com/jxa-userland/jxa/llms.txt Executes a raw JXA code string directly through `osascript`. This is useful when dynamically generating code or integrating with other tooling that produces JXA source as a string. ```APIDOC ## `@jxa/run` — `runJXACode(code: string): Promise` ### Description Executes a raw JXA code string directly through `osascript`. Useful when dynamically generating code or integrating with other tooling that produces JXA source as a string. ### Usage Examples 1. **Execute a raw JXA code string to get the current username** ```ts import { runJXACode } from "@jxa/run"; (async () => { const result = await runJXACode(` var app = Application("System Events"); app.currentUser().name(); `); console.log(result); // => "jdoe" })(); ``` 2. **Get Safari's front tab URL as a string** ```ts import { runJXACode } from "@jxa/run"; (async () => { const url = await runJXACode(` var safari = Application("Safari"); safari.windows[0].currentTab.url(); `); console.log(url); // => "https://example.com" })(); ``` ``` -------------------------------- ### Automation Namespace for Logging and Display Source: https://context7.com/jxa-userland/jxa/llms.txt Utilize the global Automation object for logging and display utilities within JXA scripts. Requires importing @jxa/global-type and using the @jxa/run utility. ```typescript import "@jxa/global-type"; import { run } from "@jxa/run"; await run(() => { // Log a value to the Script Editor console Automation.log("Running automation script"); // Get a human-readable display string for any JXA value const app = Application("Finder"); const displayStr: string = Automation.getDisplayString(app); Automation.log(displayStr); // => "Application(\"Finder\")" }); ``` -------------------------------- ### Run JXA functions with arguments Source: https://context7.com/jxa-userland/jxa/llms.txt Use `run` to execute JXA functions from Node.js. Functions and their arguments are serialized and executed in an isolated JXA environment. All data must be passed explicitly as arguments. ```typescript import "@jxa/global-type"; import { run } from "@jxa/run"; // 1. No arguments — get the current logged-in username const currentUserName = (): Promise => run(() => { return Application("System Events").currentUser().name(); }); // 2. Pass arguments explicitly — greet by name const greet = (name: string): Promise => run((name) => { return "Hello, " + name + "!"; }, name); // 3. Multi-argument — set a Finder label on a path const setLabel = (filePath: string, labelIndex: number): Promise => run((filePath, labelIndex) => { const finder = Application("Finder"); finder.items.byName(filePath).labelIndex = labelIndex; }, filePath, labelIndex); (async () => { const user = await currentUserName(); console.log(user); // => "jdoe" const msg = await greet("macOS"); console.log(msg); // => "Hello, macOS!" const version = await run(() => Application("Safari").version()); console.log(version); // => "17.4.1" })(); ``` -------------------------------- ### Transform SDEF to DTS with @jxa/sdef-to-dts Source: https://context7.com/jxa-userland/jxa/llms.txt Parses raw .sdef XML content and generates TypeScript declaration strings. Commands become typed interface methods, and record types/classes become TypeScript interfaces with proper inheritance. Optional parameters are compiled into named option types. Ensure input .sdef files and an output directory are prepared. ```typescript const fs = require("fs"); const path = require("path"); const { transform } = require("@jxa/sdef-to-dts"); const sdefDir = path.join(__dirname, "./input"); const outputDir = path.join(__dirname, "./output"); (async () => { const files = fs.readdirSync(sdefDir).filter((f: string) => f.endsWith(".sdef")); await Promise.all(files.map(async (filename: string) => { const namespace = path.basename(filename, ".sdef").replace(/\s/g, ""); const sdefContent = fs.readFileSync(path.join(sdefDir, filename), "utf-8"); try { const dtsContent = await transform(namespace, sdefContent); const outPath = path.join(outputDir, `${namespace}.d.ts`); fs.writeFileSync(outPath, dtsContent, "utf-8"); console.log(`Generated: ${outPath}`); } catch (err) { console.error(`Failed to transform ${filename}:`, err); } })); console.log("Done."); // Generated output looks like: // export namespace Safari { // export interface Application {} // export interface Document { ... } // export interface Window { ... } // } // export interface Safari extends Safari.Application { // openLocation(theURL: string): void; // ... // } })(); ``` -------------------------------- ### `@jxa/sdef-to-dts` — Library API: `transform(namespace, sdefContent)` Source: https://context7.com/jxa-userland/jxa/llms.txt The `transform` function parses raw `.sdef` XML content and returns a TypeScript declaration string. Commands become typed interface methods; record types and classes become TypeScript interfaces with proper inheritance; optional parameters are compiled into named option types. ```APIDOC ## `transform(namespace, sdefContent)` ### Description Parses raw `.sdef` XML content and returns a TypeScript declaration string. Commands become typed interface methods; record types and classes become TypeScript interfaces with proper inheritance; optional parameters are compiled into named option types. ### Parameters * **namespace** (string) - Required - The namespace for the generated types. * **sdefContent** (string) - Required - The raw `.sdef` XML content. ### Returns * **Promise** - A Promise that resolves to the generated TypeScript declaration string. ### Example ```javascript const fs = require("fs"); const path = require("path"); const { transform } = require("@jxa/sdef-to-dts"); const sdefDir = path.join(__dirname, "./input"); const outputDir = path.join(__dirname, "./output"); (async () => { const files = fs.readdirSync(sdefDir).filter((f: string) => f.endsWith(".sdef")); await Promise.all(files.map(async (filename: string) => { const namespace = path.basename(filename, ".sdef").replace(/\s/g, ""); const sdefContent = fs.readFileSync(path.join(sdefDir, filename), "utf-8"); try { const dtsContent = await transform(namespace, sdefContent); const outPath = path.join(outputDir, `${namespace}.d.ts`); fs.writeFileSync(outPath, dtsContent, "utf-8"); console.log(`Generated: ${outPath}`); } catch (err) { console.error(`Failed to transform ${filename}:`, err); } })); console.log("Done."); })(); ``` ``` -------------------------------- ### Clear REPL Buffer and History Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/repl/README.md Use the `.clear` command in the REPL to clear the current input buffer and command history. This action also releases any defined variables. ```bash .clear ``` -------------------------------- ### Execute raw JXA code strings Source: https://context7.com/jxa-userland/jxa/llms.txt Use `runJXACode` to execute arbitrary JXA code strings directly via `osascript`. This is useful for dynamically generated code or integration with other tools. ```typescript import { runJXACode } from "@jxa/run"; (async () => { // Execute a raw JXA code string const result = await runJXACode(` var app = Application("System Events"); app.currentUser().name(); `); console.log(result); // => "jdoe" // Get Safari's front tab URL as a string const url = await runJXACode(` var safari = Application("Safari"); safari.windows[0].currentTab.url(); `); console.log(url); // => "https://example.com" })(); ``` -------------------------------- ### Import JXA Global Types for Editor Autocomplete Source: https://github.com/jxa-userland/jxa/blob/master/README.md Import '@jxa/global-type' in your TypeScript files to enable typing and auto-completion for JXA. Ensure your editor supports TypeScript. ```typescript // Your .ts file require @jxa/global-type import "@jxa/global-type"; // your JXA application const userName = Application("System Events").currentUser().name(); ``` -------------------------------- ### Import @jxa/global-type for Global Application Typing Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/global-type/README.md Import this package to automatically inject JXA Application types into the global scope. This enables auto-completion for JXA applications in your editor. ```typescript import "@jxa/global-type"; // your JXA application var userName = Application("System Events").currentUser().name(); ``` -------------------------------- ### Reference @jxa/global-type via tsconfig.json Source: https://github.com/jxa-userland/jxa/blob/master/packages/@jxa/global-type/README.md Alternatively, reference the type definition file directly in your tsconfig.json. This method also enables global JXA Application typing for auto-completion. ```typescript /// // your JXA application var userName = Application("System Events").currentUser().name(); ``` -------------------------------- ### `@jxa/global-type` — Global Type Injection Source: https://context7.com/jxa-userland/jxa/llms.txt Importing `@jxa/global-type` augments the TypeScript global scope with JXA globals like `Application`, `Automation`, `ObjectSpecifier`, `Path`, `delay`, `ObjC`, and `$`. This enables full autocomplete and type checking for JXA globals in any `.ts` file without modifying `tsconfig.json`. ```APIDOC ## `@jxa/global-type` — Global Type Injection via Import ### Description Importing `@jxa/global-type` augments the TypeScript global scope with `Application`, `Automation`, `ObjectSpecifier`, `Path`, `delay`, `ObjC`, and `$`. This enables full autocomplete and type checking for JXA globals in any `.ts` file without modifying `tsconfig.json`. ### Usage **Method 1: ES import (recommended)** ```ts import "@jxa/global-type"; // Now JXA globals are typed: const sys = Application("System Events"); const user = sys.currentUser().name(); // string — autocomplete works // delay() is typed and available globally delay(2); // pause 2 seconds // Path() creates a macOS path object const p = Path("/Users/jdoe/Desktop"); // ObjC bridge is available as `ObjC` and `$` ObjC.import("Foundation"); const str = $.NSString.alloc.initWithUTF8String("hello"); ``` **Method 2: Triple-slash reference** ```ts /// // After this reference, JXA globals are typed: const mail = Application("Mail"); mail.  // Autocomplete for Mail application methods and properties ``` ``` -------------------------------- ### Global Type Injection for JXA Source: https://context7.com/jxa-userland/jxa/llms.txt Importing `@jxa/global-type` injects JXA global types like `Application`, `Path`, and `ObjC` into the TypeScript global scope. This enables editor autocomplete and static type checking without `tsconfig.json` modifications. ```typescript // method 1: ES import (recommended) import "@jxa/global-type"; // method 2: triple-slash reference /// // After either import, all JXA globals are typed: const sys = Application("System Events"); const user = sys.currentUser().name(); // string — autocomplete works // delay() is typed and available globally delay(2); // pause 2 seconds // Path() creates a macOS path object const p = Path("/Users/jdoe/Desktop"); // ObjC bridge is available as `ObjC` and `$` ObjC.import("Foundation"); const str = $.NSString.alloc.initWithUTF8String("hello"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.