This is a plugin for Obsidian that allows to customize attachment location with tokens (${noteFileName}
, ${date:format}
, etc) like typora.
- Modify location for attachment folder.
- Modify file name for Pasted Files.
- Collect attachments - take all attachments from the notes and puts them into the corresponding configured folders.
- Same to "Files & Links -> Default location for new attachments".
- Put "./" at the beginning of the path if you want to use relative path.
- See available tokens.
- example:
assets/${noteFileName}
,./assets/${noteFileName}
,./assets/${noteFileName}/${date:YYYY}
- See available tokens.
- example:
${originalAttachmentFileName}-${date:YYYYMMDDHHmmssSSS}
,${noteFileName}-img-${date:YYYYMMDD}
- Obsidian default:
Pasted image ${date:YYYYMMDDHHmmss}
.
Format for the URL that will be inserted into Markdown.
- See available tokens.
Warning
This setting is needed for very specific use cases. For majority of users, it should stay blank.
- If set, all links to attachments will be created as markdown links, even if Obsidian settings are configured to use
[[Wikilinks]]
. - If set to
${generatedAttachmentFilePath}
, it is almost the same as leaving it blank, considering the previous bullet point. Leave this setting blank instead. - If set to
${noteFilePath}
, the most likely it is not what you need, as it will insert link to the note itself, instead of the attachment files. Some users reported they have this incorrect value set automatically during the invalid update. Leave this setting blank instead.
Automatically update attachment folder name if Location for New Attachments contains ${noteFileName}
.
Automatically update attachment files in target md file if Generated attachment file name contains ${noteFileName}
.
Automatically replace special characters in attachment folder and file name with the specified string.
Automatically set all characters in folder name and pasted image name to be lowercase.
Paste images from clipboard converting them to JPEG.
The smaller the quality, the greater the compression ratio.
If enabled and Convert pasted images to JPEG
setting is enabled, images drag&dropped into the editor will be converted to JPEG.
If enabled, only image files will be renamed.
If disabled, all attachment files will be renamed.
If enabled, pasted copied files with known names will be renamed.
If disabled, only clipboard image objects (e.g., screenshots) will be renamed.
If enabled, attachments dragged and dropped into the editor will be renamed according to the Generated attachment file name setting.
If enabled, attachments processed via Collect attachments
commands will be renamed according to the Generated attachment file name setting.
When you are pasting/dragging a file with the same name as an existing file, this separator will be added to the file name.
E.g., when you are dragging file existingFile.pdf
, it will be renamed to existingFile 1.pdf
, existingFile 2.pdf
, etc, getting the first name available.
Default value is ␣
(space
).
If enabled, empty attachment folders will be preserved, useful for source control purposes.
If enabled, when the note is deleted, its orphan attachments are deleted as well.
The following tokens can be used in the Location for New Attachments, Generated attachment file name and Markdown URL format settings.
Token strings: ${token}
or ${token:format}
. token
is case-insensitive. format
is case-sensitive. When ${token}
is used, format
is empty string.
Size of the attachment file.
Format:
B
n
(default): size in bytes rounded ton
decimal points.n
is a number (0
if omitted).KB
n
: size in kilobytes rounded ton
decimal points.n
is a number (0
if omitted).MB
n
: size in megabytes rounded ton
decimal points.n
is a number (0
if omitted).
Current date/time.
Format: Moment.js formatting.
Frontmatter value of the current note.
Format: frontmatter key. Nested keys are supported, e.g., key1.key2.3.key4
.
The generated file name of the attachment (available only inside Markdown URL format setting).
Format:
- (default): Unchanged file name. Example:
foo/bar/baz qux quux.pdf
->baz qux quux
. left
n
: Leftn
characters of the file name. Exampleleft2
:foo/bar/baz qux quux.pdf
->ba
.lower
: Lowercase file name. Example:foo/bar/Baz QUX quux.pdf
->baz qux quux
.right
n
: Rightn
characters of the file name. Exampleright2
:foo/bar/baz qux quux.pdf
->ux
.slug
: Slugified file name. Example:foo/bar/baz qux quux.pdf
->baz-qux-quux
.upper
: Uppercase file name. Example:foo/bar/Baz QUX quux.pdf
->BAZ QUX QUUX
.
The generated file path of the attachment (available only inside Markdown URL format setting).
Example: foo/bar/baz.pdf
-> foo/bar/baz.pdf
.
The heading above the cursor in the note editor where the attachment is inserted.
Format:
- (default)
any
: Heading of the nearest any level#...# Heading
. 1
: Heading of the nearest# Heading
.2
: Heading of the nearest## Heading
.3
: Heading of the nearest### Heading
.4
: Heading of the nearest#### Heading
.5
: Heading of the nearest##### Heading
.6
: Heading of the nearest###### Heading
.
Note file creation date/time.
Format: Moment.js formatting.
Note file modification date/time.
Format: Moment.js formatting.
Current note file name.
Format:
- (default): Unchanged file name. Example:
foo/bar/baz qux quux.md
->baz qux quux
. left
n
: Leftn
characters of the file name. Exampleleft2
:foo/bar/baz qux quux.md
->ba
.lower
: Lowercase file name. Example:foo/bar/Baz QUX quux.md
->baz qux quux
.right
n
: Rightn
characters of the file name. Exampleright2
:foo/bar/baz qux quux.md
->ux
.slug
: Slugified file name. Example:foo/bar/baz qux quux.md
->baz-qux-quux
.upper
: Uppercase file name. Example:foo/bar/Baz QUX quux.md
->BAZ QUX QUUX
.
Current note full path.
Example: foo/bar/baz.md
-> foo/bar/baz.md
.
Current note's folder name.
Format:
-
(default): Unchanged folder name. Example:
foo/bar baz qux/quux.md
->bar baz qux
. -
left
n
: Leftn
characters of the folder name. Exampleleft2
:foo/bar baz qux/quux.md
->ba
. -
lower
: Lowercase folder name. Example:foo/Bar BAZ qux/quux.md
->bar baz qux
. -
right
n
: Rightn
characters of the folder name. Exampleright2
:foo/bar baz qux/quux.md
->ux
. -
slug
: Slugified folder name. Example:foo/bar baz qux/quux.md
->bar-baz-qux
. -
upper
: Uppercase folder name. Example:foo/Bar BAZ qux/quux.md
->BAR BAZ QUX
. -
indexFromEnd
n
: 0-based index from the end of the folder tree. ExampleindexFromEnd1
:foo/bar/baz/qux/quux.md
->baz
. -
indexFromStart
n
: 0-based index from the start of the folder tree. ExampleindexFromStart1
:foo/bar/baz/qux/quux.md
->bar
.
You can combine both kind of format formats, having indexFrom...
first:
indexFromEnd
n
,left
m
. Example:indexFromEnd1,left2
:foo/bar/baz/qux/quux.md
->ba
(first two characters ofbaz
).
Current note's folder full path.
Example: foo/bar/baz.md
-> foo/bar
.
Extension of the original attachment file.
Example: foo.bar.pdf
-> pdf
.
File name of the original attachment file.
Format:
- (default): File name as is. Example:
foo bar.baz.pdf
->foo bar.baz
. left
n
: Leftn
characters of the file name. Exampleleft2
:foo/bar baz qux/quux.pdf
->ba
.lower
: Lowercase folder name. Example:foo Bar.BAZ.pdf
->foo bar.baz
.right
n
: Rightn
characters of the folder name. Exampleleft2
:foo/bar baz qux/quux.pdf
->ux
.slug
: Slugified file name. Example:foo bar.baz.pdf
->foo-bar-baz
.upper
: Uppercase folder name. Example:foo Bar.BAZ.pdf
->FOO BAR.BAZ
.
The value asked from the user prompt.
Also in the prompt modal, you can preview the file, if it is supported by Obsidian (image, video, pdf).
Format:
- (default): Unchanged value entered by user. Example:
foo bar
->foo bar
. left
n
: Leftn
characters of the value entered by user. Exampleleft2
:foo bar
->fo
.lower
: Lowercased value entered by user. Example:foo Bar
->foo bar
.right
n
: Rightn
characters of the value entered by user. Exampleright2
:foo bar
->ar
.slug
: Slugified value entered by user. Example:foo bar.baz
->foo-bar-baz
.upper
: Uppercased value entered by user Example:foo Bar
->FOO BAR
.
Random value.
Format:
D
n
:n
random digits.n
is a number (1
if omitted).L
n
:n
random letters.n
is a number (1
if omitted).DL
n
:n
random digits or letters.n
is a number (1
if omitted).uuid
: Random UUID.
You can define custom tokens in the Custom tokens
setting.
The custom tokens are defined as functions, both sync and async are supported.
Example:
registerCustomToken('foo', (ctx) => {
return ctx.noteFileName + ctx.app.appId + ctx.format + ctx.obsidian.apiVersion;
});
registerCustomToken('bar', async (ctx) => {
await sleep(100);
return ctx.noteFileName + ctx.app.appId + ctx.format + ctx.obsidian.apiVersion;
});
registerCustomToken('baz', async (ctx) => {
return ctx.noteFileName + await ctx.fillTemplate('corge ${grault} garply ${waldo:fred} plugh');
});
Then you can use the defined ${foo}
, ${bar:xyzzy}
tokens in the Location for New Attachments, Generated attachment file name and Markdown URL format settings.
See spec of the ctx
argument.
All notable changes to this project will be documented in the CHANGELOG.
The plugin is available in the official Community Plugins repository.
To install the latest beta release of this plugin (regardless if it is available in the official Community Plugins repository or not), follow these steps:
- Ensure you have the BRAT plugin installed and enabled.
- Click Install via BRAT.
- An Obsidian pop-up window should appear. In the window, click the
Add plugin
button once and wait a few seconds for the plugin to install.
By default, debug messages for this plugin are hidden.
To show them, run the following command:
window.DEBUG.enable('obsidian-custom-attachment-location');
For more details, refer to the documentation.
Maintainer: Michael Naumov