Action
Save to Purgatory
Saves draft to a markdown file in the specified directory without choosing the path after each launch.
First Run / Action Items
- In Line 3, change the bookmark name to be applicable to what directory you will be setting. JUST THE NAME, NOT PATH! Example below
const BOOKMARK_NAME = "Purgatory"; // Change bookmark name to be applicable
- Upon first launch, it will have you choose the path where this action will automatically save to. This will then set the bookmark name to the path chosen and never ask you again.
- The action will always prompt you for a title/file name.
Example Usage:
I have this configured to point to my “Purgatory” directory which will save the draft to that directory as markdown. That specific directory has a hazel rule that auto-purges 30 days after it has been added.
On first-run, it will make you select the Purgatory folder in order for it to make a bookmark called “Purgatory” within drafts so it is able to write to the existing directory.
—
X: https://x.com/deanfx
Mastodon: https://twit.social/@deanfx
Bluesky: https://bsky.app/profile/deanfx.bsky.social
Steps
-
script (macOS only)
// First run will prompt ONCE to choose the folder for the bookmark. const BOOKMARK_NAME = "Purgatory"; // Change bookmark name to be applicable // Default filename let defaultName = draft.processTemplate("[[safe_title]]") || "Untitled"; defaultName = defaultName.replace(/\s+/g, " ").trim(); // Prompt for filename let p = Prompt.create(); p.title = "Save as Markdown"; p.addTextField("fileName", "Name", `${defaultName}.md`); p.addButton("Save"); p.addButton("Cancel"); if (!p.show() || p.buttonPressed === "Cancel") context.cancel(); let fileName = (p.fieldValues["fileName"] || "").trim(); if (!fileName) context.fail("Filename cannot be blank."); if (!fileName.toLowerCase().endsWith(".md")) fileName += ".md"; // Bookmark + FileManager (outside sandbox) let bm = Bookmark.findOrCreate(BOOKMARK_NAME); let fm = FileManager.createForBookmark(bm); // IMPORTANT: paths are relative to the bookmark root, and must start with "/" let path = "/" + fileName; let ok = fm.writeString(path, draft.content); if (!ok) context.fail("Failed to write file to bookmark: " + BOOKMARK_NAME + path); // Optional: confirmation alert(`Saved to bookmark “${BOOKMARK_NAME}”:\n${path}`);
Options
-
After Success Default Notification Info Log Level Info