Paste image rename plugin

Hi there, I’m glad to share my third plugin: Obsidian paste image rename.

This plugin is inspired by Zettlr, Zettlr shows a prompt that allows the user to rename the image, this is a great help if you want your images to be named and organized clearly.

Zettlr's prompt after pasting an image

Paste image rename plugin not only implements Zettlr’s feature, but also allows you to customize how the image name would be generated, and eventually free you from the hassle by automatically renaming the image according to the rules.

Installation

The plugin has been added to community plugins, you can now search “Paste image rename” to install it.

Currently this plugin is in review, but you can take a try by either way below:

  1. Manually download the latest release from GitHub and extract the files in $YOUR_VAULT/.obsidian/plugins/obsidian-paste-image-rename.
  2. Use BRAT plugin

How to use

Basic usage

After installing the plugin, you can just paste an image to any document, and the rename prompt will display:

By typing the new name and clicking “Rename” (or just press enter), the image will be renamed and the internal link will be replaced to the new name.
If you set “Image name pattern” to {{fileName}} (it’s the default behavior after 1.2.0),
“New name” will be generated as the name of the active file.

Set imageNameKey frontmatter

While adding a lot of images to one document, people possibly want the images to be named in the same format. That’s where imageNameKey is helpful.

First set a value for imageNameKey in frontmatter:

---
imageNameKey: my-blog
---

Then paste an image, you will notice that the “New name” has already been generated as “my-blog”, which is exactly the value of imageNameKey:

You can change the pattern for new name generating by updating the “Image name pattern” value in settings.

For detailed explanation, and other features such as auto renaming, please refer to Settings.

Add prefix/suffix to duplicated names

The plugin will always try to add a prefix/suffix if there’s a file of the same name.

Let’s continue from the last section and paste the second image, the prompt will still show the new name as “my-blog”, now if we just click “Rename”, the file will be renamed as “my-blog-1.png”, not “my-blog.png”:

The -1 suffix is generated according to the default settings:

  • Because “Duplicate number at start” is false, suffix is used rather than prefix
  • “Duplicate number delimiter” - is put before the number 1

If we paste the third image without editing the “New name” input, its name will be “my-blog-2.png”, the number is increased according to the largest number of “my-blog-?.png” in the attachment directory.

This feature is especially powerful if you enable “Auto rename” in settings, you can just add new images without thinking, and they will be renamed sequentially by the pattern and imageNameKey set.


Have fun.

12 Likes

Released 1.1.0:

  • add handleAllImages setting, allow renaming for drag’n drop

Released 1.2.0:

  • add {{fileName}} variable for imageNamePattern

The plugin has been added to community plugins, you can now search “Paste image rename” to install it.

3 Likes

Thanks for this plugin, that’s exactly what i needed.

Just one issue : if you disable the prompt, then the plugin duplicate the image with the new name in the folder… but the old image stay with the old name on the note.

So, the plugin is not usable like this for now.

Thank you again for your time :slight_smile:

Hi Damien, thanks for the feedback, but I cannot reproduce the issue you encounter, can you repost it to github issues? The issue will be created with a template, you can provide more information there so that I can locate the problem more easily.

Seems not working in Obsidian v0.14.6? After installing and enabling this plugin, nothing happens when pasting images in the markdown editor.

UPDATE: finally had some clue, in my case this plugin only works for screen clips or something, not work for existing image files.

Hi dzhou,

Check this FAQ that is possibly related to this case:

Q: I pasted an image but the rename prompt did not show up.

A: This is probably because you are using the Windows system and pasting from a file (i.e. the image is copied from File Explorer, not from a browser or image viewer). In Windows, pasting from a file is like a regular file transfer, the original filename is kept rather than being created and named “Pasted image …” by Obsidian. You need to turn on “Handle all attachments” in settings to make it work in this situation.

And try to enable the “Handle all attachments” option in settings. Described here: Handle all attachments.

Also, don’t forget to update Paste image rename to the latest version.

Thanks for the quick reply.

I’m using macOS and trying to copy an image file from Finder and paste it to markdown. After enabling “Handle all attachments”, still no good.

data.json enclosed:

{
  "imageNamePattern": "{{fileName}}-{{DATE:YYYY-MM-DD-HH-mm-ss}}",
  "dupNumberAtStart": false,
  "dupNumberDelimiter": "-",
  "autoRename": false,
  "handleAllAttachments": true,
  "excludeExtensionPattern": "",
  "disableRenameNotice": false
}

Got it, I used the data.json but still cannot reproduce it, can you submit an issue here? We can discuss it further in GitHub. Sign in to GitHub · GitHub

OK, I’ll try to submit an issue.

I am having problems getting the batch renamed by the date format. See the image below:

Can anyone provide an example of how this works with the plugin settings? Its not working as shown:

{{DATE:$FORMAT}}: use $FORMAT to format the current date, $FORMAT must be a Moment.js format string, e.g. {{DATE:YYYY-MM-DD}}.

I successfully installed the plugin on my private PC with the vault on a NAS share. But when I open the vault on my business notebook the plugin refuses to work. The status is active but the screenshots stay as “Pasted image …” and no popup is showing. Any ideas?

Hello,

The plugin only works for me when I want to paste the first picture. Once I start pasting more pictures into the same note it tells me the name is duplicate and just pastes the image with the original name

Here are the plugin settings:

These are the current settings. However, I have tried with many different settings and it seems there is no way to fix this issue. For now I am just using the manual rename after paste, which is still more convenient than not using the plugin, so thank you very much for that

Here is what I get when I try to copy and paste: