Skip to content

Run JavaScript File

The run JavaScript file action runs a JavaScript file.

interface JSButtonAction {
type: 'js';
file: string; // the path to the JavaScript file to run, relative to the vault root
args?: Record<string, unknown>; // optional arguments to pass to the script (available in the script as `context.args`)
}

The button configuration is available as a read only variable in the script as context.buttonConfig. Aditional information about the button is available in the context.buttonContext object. See Button Context for more information. The args is passed to the script as context.args.

Example

```meta-bind-button
style: primary
label: Run JavaScript File
action:
type: js
file: someScript.js
args:
greeting: "Meta Bind User"
```

With the following someScript.js file in the vault root.

someScript.js
console.log('Hello ${context.args.greeting}!');

You should see the string Hello Meta Bind User! printed to the console, when you click the button.