I’m relatively new to creating custom actions and had a question:
I’m thinking of putting together an action that would read a folder in my Obsidian directory and populate a Prompt with a button for every file in that Obsidian directory.
My goal is to extend my existing action that allows me to pick which note in my /Lists directory I want to append the Draft to. The problem with my existing action is that every time I add a new file to that directory, I have to update my action to include it as an option.
Would reading through file titles and dynamically creating a prompt that lets me pick a file be possible? I’m having a bit of trouble figuring out if the Bookmark object would work for this.
Thanks for the tips! This was actually quite easy with the bookmarks feature once I knew to look for the FileManager.
let bookmark = Bookmark.findOrCreate("Lists");
let fm = FileManager.createForBookmark(bookmark);
let contents = fm.listContents("/");
let p = Prompt.create();
p.title = "Choose a list";
contents.forEach(listFile => {
p.addButton(listFile.replace(".md","").replace("/",""));
})
var didSelect = p.show();
if (didSelect) {
draft.setTemplateTag("file",p.buttonPressed);
} else {
context.cancel();
}