obsidian-cli

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Obsidian CLI

Obsidian CLI

Use the
obsidian
CLI to interact with a running Obsidian instance. Requires Obsidian to be open.
使用
obsidian
CLI 与正在运行的 Obsidian 实例交互。需要先打开 Obsidian。

Command reference

命令参考

Run
obsidian help
to see all available commands. This is always up to date. Full docs: https://help.obsidian.md/cli
运行
obsidian help
可查看所有可用命令。此内容始终保持最新。完整文档:https://help.obsidian.md/cli

Syntax

语法

Parameters take a value with
=
. Quote values with spaces:
bash
obsidian create name="My Note" content="Hello world"
Flags are boolean switches with no value:
bash
obsidian create name="My Note" silent overwrite
For multiline content use
\n
for newline and
\t
for tab.
参数使用
=
接收值。包含空格的值需要加引号:
bash
obsidian create name="My Note" content="Hello world"
标志是无需赋值的布尔开关:
bash
obsidian create name="My Note" silent overwrite
多行内容可使用
\n
表示换行,使用
\t
表示制表符。

File targeting

文件定位

Many commands accept
file
or
path
to target a file. Without either, the active file is used.
  • file=<name>
    — resolves like a wikilink (name only, no path or extension needed)
  • path=<path>
    — exact path from vault root, e.g.
    folder/note.md
许多命令接受
file
或
path
参数来指定文件。两者均未指定时,将使用当前活动文件。
  • file=<name>
    — 像 wikilink 一样解析(只需名称,无需路径或扩展名)
  • path=<path>
    — 从仓库根目录开始的精确路径,例如
    folder/note.md

Vault targeting

仓库定位

Commands target the most recently focused vault by default. Use
vault=<name>
as the first parameter to target a specific vault:
bash
obsidian vault="My Vault" search query="test"
命令默认作用于最近获得焦点的仓库。使用
vault=<name>
作为第一个参数可指定特定仓库:
bash
obsidian vault="My Vault" search query="test"

Common patterns

常用模式

bash
obsidian read file="My Note"
obsidian create name="New Note" content="# Hello" template="Template" silent
obsidian append file="My Note" content="New line"
obsidian search query="search term" limit=10
obsidian daily:read
obsidian daily:append content="- [ ] New task"
obsidian property:set name="status" value="done" file="My Note"
obsidian tasks daily todo
obsidian tags sort=count counts
obsidian backlinks file="My Note"
Use
--copy
on any command to copy output to clipboard. Use
silent
to prevent files from opening. Use
total
on list commands to get a count.
bash
obsidian read file="My Note"
obsidian create name="New Note" content="# Hello" template="Template" silent
obsidian append file="My Note" content="New line"
obsidian search query="search term" limit=10
obsidian daily:read
obsidian daily:append content="- [ ] New task"
obsidian property:set name="status" value="done" file="My Note"
obsidian tasks daily todo
obsidian tags sort=count counts
obsidian backlinks file="My Note"
任何命令都可以使用
--copy
将输出复制到剪贴板。使用
silent
可防止文件被打开。在列表类命令中使用
total
可获取数量。

Plugin development

插件开发

Develop/test cycle

开发与测试流程

After making code changes to a plugin or theme, follow this workflow:
  1. Reload the plugin to pick up changes:
    bash
    obsidian plugin:reload id=my-plugin
  2. Check for errors — if errors appear, fix and repeat from step 1:
    bash
    obsidian dev:errors
  3. Verify visually with a screenshot or DOM inspection:
    bash
    obsidian dev:screenshot path=screenshot.png
    obsidian dev:dom selector=".workspace-leaf" text
  4. Check console output for warnings or unexpected logs:
    bash
    obsidian dev:console level=error
对插件或主题进行代码更改后,请遵循以下工作流:
  1. 重新加载插件以应用更改:
    bash
    obsidian plugin:reload id=my-plugin
  2. 检查错误 — 如果出现错误,请修复后从步骤 1 重新执行:
    bash
    obsidian dev:errors
  3. 进行视觉验证,可使用屏幕截图或 DOM 检查:
    bash
    obsidian dev:screenshot path=screenshot.png
    obsidian dev:dom selector=".workspace-leaf" text
  4. 检查控制台输出,查看警告或意外日志:
    bash
    obsidian dev:console level=error

Additional developer commands

其他开发者命令

Run JavaScript in the app context:
bash
obsidian eval code="app.vault.getFiles().length"
Inspect CSS values:
bash
obsidian dev:css selector=".workspace-leaf" prop=background-color
Toggle mobile emulation:
bash
obsidian dev:mobile on
Run
obsidian help
to see additional developer commands including CDP and debugger controls.
在应用上下文中运行 JavaScript:
bash
obsidian eval code="app.vault.getFiles().length"
检查 CSS 值:
bash
obsidian dev:css selector=".workspace-leaf" prop=background-color
切换移动端模拟:
bash
obsidian dev:mobile on
运行
obsidian help
可查看其他开发者命令,包括 CDP 和调试器控制功能。