Skip to content

Instantly share code, notes, and snippets.

@mygeekdaddy
Created May 6, 2021 01:25
Show Gist options
  • Save mygeekdaddy/efdba93b5c3d1981dcdbd7f946127fde to your computer and use it in GitHub Desktop.
Save mygeekdaddy/efdba93b5c3d1981dcdbd7f946127fde to your computer and use it in GitHub Desktop.
Drafts action to import .MD files and apply tag
// Based on original script from @agiletortoise on Drafts Forum
// https://forums.getdrafts.com/t/bulk-import-text-files/2852/8
let fm = FileManager.createCloud();
let path = "/Temp";
let files = fm.listContents(path);
for (let f of files) {
// get file name from end of path
let fileName = f.split("/").pop();
// read content of file
let content = fm.readString(f);
let nvtag = fileName.split(" ")[0]
// create draft
let d = Draft.create();
d.content = fileName + "\n\n" + content;
d.addTag(nvtag);
d.addTag("nvalt")
//myStr.split(" ")[0]
d.update();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment