Skip to content

CLI Bookmarks Resource

CLIBookmarksResource(cli)

Bases: BaseCLIResource

CLI resource for bookmark operations.

Attributes:

Name Type Description
_cli

Reference to the parent ObsidianCLI instance.

Source code in src/aiobsidian/cli/_base.py
def __init__(self, cli: ObsidianCLI) -> None:
    self._cli = cli

add(*, file=None, folder=None, url=None, title=None, search=None, subpath=None) async

Add a bookmark.

At least one of file, folder, url, or search must be provided.

Parameters:

Name Type Description Default
file str | None

Path to a file to bookmark.

None
folder str | None

Path to a folder to bookmark.

None
url str | None

URL to bookmark.

None
title str | None

Display title for the bookmark.

None
search str | None

Search query to bookmark.

None
subpath str | None

Subpath within the file (e.g. heading or block).

None
Source code in src/aiobsidian/cli/bookmarks.py
async def add(
    self,
    *,
    file: str | None = None,
    folder: str | None = None,
    url: str | None = None,
    title: str | None = None,
    search: str | None = None,
    subpath: str | None = None,
) -> None:
    """Add a bookmark.

    At least one of ``file``, ``folder``, ``url``, or ``search``
    must be provided.

    Args:
        file: Path to a file to bookmark.
        folder: Path to a folder to bookmark.
        url: URL to bookmark.
        title: Display title for the bookmark.
        search: Search query to bookmark.
        subpath: Subpath within the file (e.g. heading or block).
    """
    params: dict[str, str] = {}
    if file:
        params["file"] = file
    if folder:
        params["folder"] = folder
    if url:
        params["url"] = url
    if title:
        params["title"] = title
    if search:
        params["search"] = search
    if subpath:
        params["subpath"] = subpath
    await self._cli._execute("bookmark", params=params or None)

list() async

List all bookmarks.

Returns:

Type Description
list[dict[str, Any]]

List of bookmark objects.

Source code in src/aiobsidian/cli/bookmarks.py
async def list(self) -> list[dict[str, Any]]:
    """List all bookmarks.

    Returns:
        List of bookmark objects.
    """
    output = await self._cli._execute("bookmarks")
    result: list[dict[str, Any]] = json.loads(output)
    return result