trganda / obsidian-attachment-management

Attachment Management of Obsidian
MIT License
142 stars 8 forks source link
attachment custom obsidian obsidian-plugin

Obsidian Attachment Management

This plugin supports more flexibly setting your attachment location with variables like ${notepath}, ${notename}, ${date} and ${md5}. An override setting feature can be used to change the global setting of a folder, file or extension.

Read the Original Name section before using the ${originalname} variable.

Roadmap of Features

This plugin currently supports:

How to Install

Settings

The path of attachment is composed of three parts :

{root path}/{attachment path}/{attachment name}.extension

And you can use the variables below to config:

Notice before using ${originalname}, there is something you should know. This plugin will not persist the original name, it only use the filename to generate the attachment name on create event (first time added to obsidian). This means if you have used ${originalname}, when you rearrange the attachment, there is no new name generated for the attachment, it just used the current name (i.e. change Attachment format from asset-${originalname} to asset-1-${originalname}, and use rearrange command, it's useless).

Root Path to Save New Attachments

You must select a root folder to save the attachment associated with a markdown or canvas file.

SCR-20230511-rgge

It can be set using the config of Obsidian in Files & Links and reset using this option.

Attachment Path

A sub-folder to place attachment under the {root path}, available variables:

Default value ${notepath}/${notename}.

Attachment Format

Set how to rename the attachment and available variables:

default value IMG-{date}.

Date Format

Use Moment format options to set the ${date}, default value YYYYMMDDHHmmssSSS. You should always use the ${date} variable to prevent the same file name.

Exclude Extension Pattern

This option is useful if you want to ignore some file types. Write a Regex pattern to exclude certain extensions from being handled.

SCR-20230918-pkys

Automatically Rename Attachment

Automatically rename the attachment folder/filename when you rename the folder/filename where the corresponding md/canvas file is placed.

Extension Override Setting

This feature allows you to specify the setting for a serials extension. You can use a regex pattern here to override the global setting.

SCR-20230918-pihr

Exclude Paths

If you want some paths to be skipped by this plugin, add them to the text area. If you have multiple paths, split them with a semicolon ';'.

By default, the "Exclude paths" will only work on the folder you added, and that folder contains at least one markdown file; you can toggle "Exclude subpaths" to exclude subpaths also.

The path is case-sensitive and should not have a leading slash '/' at the beginning.

Usage

Install and enable the plugin, after configuration you can paste or drop attachment file as usually and it will be auto renamed.

This plugin supports a command Rearrange linked attachments/Rearrange all linked attachments. If you run this command, it will rename all attachments (image file default, to rename another type, you need to enable Handle All Attachements) that have been linked in the markdown or canvas file as you configured.

SCR-20230511-rrtk

Notice: The Rearrange linked attachments/Rearrange all linked attachments is currently an experimental feature; if you want to try it out, it's best to back up your files first.

Overriding Setting

You can set the attachment path setting for a file or folder. The priority of these settings are:

file setting > most close parent folder setting > global setting

If you want to reset the settings of files or folders to the global setting, use the command Reset Override Setting or the Reset button on the override setting panel. The reset will only work on each file or folder that you trigger the command on. A more appropriate method to handle resetting will be added in the future.

Original Name

The ${originalname} represents the original filename (without extension) of the attachment you added to the vault. Some people want to keep the original filename and/or combine it with other variables like ${date}. If you want to keep the original filename of an attachment, set the Attachment Format with ${originalname}.

If you want to use ${originalname} with other variables, like ${originalname}-${date}. This plugin will persist the original name for future use. Suppose you change the Attachment Format from ${originalname}-${date} to IMG-${originalname}, it's work fine.

The original name is stored in data.json, the configuration file of the plugin. You can find it at .obsidian/plugins/attachment-management/data.json.

  "originalNameStorage": [
    {
      "n": "Pasted image 20240113222517",
      "md5": "9B1546EBA299E1A2A2FC86C664A15073"
    }
  ],

As you can see, the original name was saved with a hash, so if you add the same file multiple times, only the last one will be saved. The originalNameStorage will not clear automatically, use command Clear unused original name storage. This command will keep the entry if the hash of an attachment is matched.

Known Issues

Screen Recording

FAQ

Q: What if I add '/' to Exclude Paths?

A: It will exclude the whole vault folder.