API: Get the directory of the 'Default location for new attachments' setting

Use case or problem

My Shell commands plugin has some variables that can be used to pass data from Obsidian to shell commands when executing them. For example, there is a {{file_name}} variable that passes the currently open note’s file name to a shell command.

I’d like to create a variable for the directory that has been configured as the default location for new attachments. That would allow executing shell commands that e.g. procude new files into the attachment directory, such as PDFs.

Proposed solution

Obsidian API already provides a method for getting the default directory for new notes. I’m suggesting to add a similar kind of method for attachments.

Thank you for considering this! :slightly_smiling_face:

This is already there, just not documented in the spec.

This function would give you the exact location where to save a specific attachement according to the setting:

You can also acess the raw settings value with:
Using this value can be dangerous, the returned value might be a bit unexpected depending on what the setting is set to, better to use the other method if possible.

1 Like

Thank you, this is valuable! :slightly_smiling_face:

Maybe Obsidian could introduce this method in the public API? I think I’ll hold on a bit to see it makes it to the public API, then I’d be more on a safe side. But it’s anyway good to know this method in case I’d need it urgently.

This is also nice to know! :sunglasses: