Paste images based on file location

Things I have tried

  • Tried to find any settings related to pasting images in the “Files and Links” section in Obsidian Settings
  • Tried to find a plugin, and found one (paste image rename) but it solves only a part of the request

What I’m trying to do

I have 2 topics, A and B, with many subtopics folders and notes in each of them (topics A and B are separate folders, with many subfolders and notes in them). Whenever I paste an image in any file of topic A (i.e., the first folder), I want the images to be pasted in an Attachment folder A’ (outside A), and when I paste an image in a file present in the folder of topic B, I want it to be pasted in a separate folder B’ (anywhere outside B).

I don’t know how to achieve this – pasting an image based on the location of the note in which it is being placed.

Also, by pasting an image, I mean pasting screenshots and other local images (from outside the vault)![[...]] and not embedding the images from the web![](....) and yeah, the folders A, B, A’ and B’ are in the same vault.

This is more food for thoughts, rather than a concrete idea/implementation. But, this might be possible if you paste the image, and then insert a template afterwards, where the template moves the image file accordingly to the file path.

I think that should be doable using the Templater plugin, as it should have all the necessary components to both check the current file both for contents, and for moving files around. It’ll need a little bit of coding, though.

It could possibly be achieved using DataviewJS also, but that would even more coding and dependency on javascript logic/functions.

The only line I have ever used in templater is <%tp.date()%>.
Can you tell me how to do what I want using templater? If that feels time-consuming, please suggest to me some basic tutorials on it.

I can provide you with a little more pseudocode variant of it, but I’m not sure where to find tutorials to get to that level of coding if you don’t know coding beforehand.

I’m visualising something like the following:

  • Have a static table/list, giving the attachment folder for a given folder
  • Get the file path of current file, to help determine end location
  • get the full content of the current file
    • Scan it for any embeds/images…
    • … and check each of them for their full file path
    • If some are not in the correct location, move them

I don’t think I’m motivated to actually code this myself, sorry, but it should be doable if you got some coding experience.

1 Like

Thanks, with the documentation, I think I can write the code

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.