Actions

unlisted

by @mcmanussliam

Create and manage custom `shell` or `js` actions that can run on either a schedule, via command palette, or in response to file events.

4 starsUpdated 3mo ago0BSD
View on GitHub

Obsidian Code View Banner

Obsidian

Obsidian Actions

Actions is an Obsidian plugin that allows you to define custom shell or javascript actions which are then triggered by a variety of hooks. These actions can manipulate files, execute scripts, or automate workflows inside your Obsidian vault.

I designed it to be as flexible as possible, exposing a controlled environment of variables and methods to help you template your scripts.

## Features

  • define manual, startup, event-based, or interval-based actions.
  • support for both javascript and shell commands.
  • use template variables to dynamically access file and editor context.
  • supports cron styled scheduled actions with interval hooks.

Installing

If you are manually installing the plugin:

  • copy main.js, styles.css, and manifest.json into [your_vault_folder]/.obsidian/plugins/actions
  • enable the plugin from Obsidian settings → Community Plugins → Actions Plugin.

If you are developing:

  • clone the repo
  • install dependencies, npm ci, if you are ever to add new dependencies please always lock the version, the days of ^ are long gone.
  • create a symlink from your plugin folder to your obsidian vault.
    • on macOS / Linux ln -s /full/path/to/your/repo /full/path/to/your/vault/.obsidian/plugins/actions-plugin
  • start watch mode to compile TypeScript automatically npm run dev
  • then enable the plugin in Obsidian and you should see your changes reflected.

Using the Plugin

  • open Settings -> Actions.
  • create a new action using the Create button.
  • configure the action:
    • name, displayed in the ui and used to generate the action id.
    • icon, choose any Lucide icon
    • description, optional description shown in settings.
    • hook, determines when the action runs; manual, startup, interval, or on events.
    • type, js or shell.
    • code, the command or script to execute.
    • schedule, required if using an interval hook, in cron format.
  • save the action. You can now execute it manually or wait for its hook trigger.

Wanna know more about the Plugin?

Hooks?

Hooks determine when your action runs:

HookDescription
manualExecutes only when manually triggered via the settings or command palette.
startupExecutes automatically when Obsidian loads.
intervalExecutes on a schedule using cron syntax, * * * * *.
createFileExecutes whenever a new file is created in the vault.
modifyFileExecutes whenever a file is modified.
deleteFileExecutes whenever a file is deleted.
renameFileExecutes whenever a file is renamed.

Interval hooks require a valid cron schedule. See crontab.guru for examples.

Command Types?

javascript

js actions are executed in a controlled environment with access to a subset of the Obsidian API and helper functions, this includes:

  • app
  • vault
  • workspace
  • metadataCache
  • fileManager
  • Notice
  • Modal
  • Setting
  • FuzzySuggestModal
  • exec

This can allow you to do some really interesting code:

new Notice('Hello World!'); // displays a notice in Obsidian
console.log(app.vault.getFiles()); // logs in the Obsidian console
exec('echo "{{path}}"'); // execs a shell command with an environment variable

shell

shell actions execute code in a plain shell. It's useful for running scripts, git commands, or other cli tools:

git add .
git commit -m "Update"
git push

Environment Variables?

Actions have access to dynamic variables reflecting the current file and editor context.

VariableDescription
pathAbsolute file path.
relative_pathFile path relative to vault root.
extensionFile extension.
readonlyTrue if the editor is read-only.
selectedSelected text in the editor.
selected_lowerLowercase selected text.
selected_upperUppercase selected text.
length_selectedLength of selected text.
word_countWord count of file or selection.
line_indexCursor line index (0-based).
column_indexCursor column index.
vault_nameName of the vault.
file_nameFile name without extension.
file_name_with_extFile name with extension.
contentFull file content.
content_lengthLength of file content.
timestampISO timestamp of execution.
dateHuman-readable date.
timeHuman-readable time.
hello_worldTest variable for experimentation.

We use Mustache templates for this.

echo "Processing file {{file_name}} at {{time}}"

For plugin developers

Search results and similarity scores are powered by semantic analysis of your plugin's README. If your plugin isn't appearing for searches you'd expect, try updating your README to clearly describe your plugin's purpose, features, and use cases.