Save Pasted images as Pasted-image-DATE with - instead of spaces

Use case or problem

When doing things with the images in a vault it is more difficult because the image names have spaces in them. The main reason for this is that the images are stored with spaces but in the notes you have to use %20 to refer to these spaces.

I tried to make a program to move files around the %20 just makes it more complicated.

Proposed solution

Replace the spaces in the autogenerated name with -.

Current workaround (optional)

Right now I am using regexes like this to deal with spaces and just renaming it myself to -.

import re
image_with_spaces_pattern = re.compile(r'(!\[.+]\([.\\/A-z0-9]+)(%20)([A-z 0-9.%]+\))')

while re.search(image_with_spaces_pattern, text):
    text = re.sub(image_with_spaces_pattern, r'\1-\3', text)

This pattern is for markdown links.

1 Like

Do you mean embed the image which is an attachment in the vault?

image

I don’t understand what you mean. I am just talking about the name obsidian generates when you paste an image into a note in the vault. They are usually PASTED IMAGE DATE I think it would be better if these names are seperated with - or _ instead of spaces as the spaces are turned into %20 and the _ and - just stay the same.

Use case or problem

When I paste a screenshot into a document, there are spaces in the image name, such as: '! [[Pasted image xxx.png]]`
Whenever I want to upload an image to my image hosting, I usually need to change the image name to remove the spaces

Proposed solution

The spaces in the image name are replaced by -, i.e. ! [[Pasted image xxx.png]]! [[Pasted-image-xxx.png]]

3 Likes

I don’t have the same problem on macOS.
What OS are you using?

Version : macOS Ventura

If the image name contains spaces, it will cause the URL of my image hosting to be weird

1 Like

The Shortcuts gallery on macOS has a ‘Rename Files’ shortcut that can find spaces and replace them with hyphens, underscores, etc. Works on multiple files at once. I use it all the time for the reasons you outlined in the first post.

But this means that if I forget to rename the image and upload it, I get a URL with spaces in it, which in fact happens quite often

Version : macOS Ventura

I copied image from PDF and pasted it into Obsidian

The plugin that @anon63144152 mentioned is supposed to rename automatically for you, so that you can’t forget.

I have not used Shortcuts Gallery , but I found a plugin that basically meets the needs

1 Like

Thank you for reminding me to look for the plugin

Another easy solution is to create a simple Automator ‘Folder Action’ to change spaces in file names to underscores (or hyphens). Any file that is dropped into the specified folder will automatically be renamed. You can then drop files into Obsidian. Also useful if you want to rename files that aren’t going to be used in Obsidian.

3 Likes

I’m not sure if my configuration is wrong, Automator can rename images, but the internal links on Obsidian don’t update automatically

I think @anon63144152 said that you have to drop into a (non-Obsidian) folder first. Once it’s renamed by Automator, you can then drop the files into Obsidian.

But really it sounds like GitHub - reorx/obsidian-paste-image-rename: Rename pasted images and all the other attchments added to the vault would work a lot better for what you want since you don’t need a two-step process.

2 Likes

I think so, maybe our use cases are not the same

1 Like

I don’t have a use case. This is for you. Just addressing what you asked for.

Maybe what I just said was ambiguous, I mean me and @anon63144152 might have different use cases.Thanks a lot.

Duplicate of Save Pasted images as Pasted-image-DATE with - instead of spaces

1 Like