Action
Add to Programming-List (does not work as intended)
Posted by Ro136,
Last update
almost 3 years ago
- Unlisted
This is a modified version of the “Add to list” action by @agiletortoise
With this setting, it somehow creates a new draft everytime, instead of appending it, when the 2nd “Drafts (Actions - JavaScript)” category is selected.
Hoping to understand the reason for this behaivior
Thank you.
Prompt user to select a category, and append the text of the draft to a list in a draft tagged “lists”, with a header for the category. Intended as an example of how to maintain lists of ideas, movies you want to remember, etc.
To modify available categories, edit the “Define Template Tag” step, listing one category per line.
Steps
-
defineTemplateTag
name categories
template Apple shortcuts Drafts (Actions - JavaScript)
-
script
/* Ask for a category, and append to a tagged list for that category */ // tag to assign to list drafts const listTag = "programming-lists"; // setup categories available // based on "Define Template Tag" step const categories = draft.processTemplate("[[categories]]").trim().split("\n"); // grab current draft const currentContent = draft.content.trim();; // prompt to select a category let p = Prompt.create(); p.title = "Select list"; for (let cat of categories) { p.addButton(cat); } if (p.show()) { // user made a selection let category = p.buttonPressed; // query for list drafts... let drafts = Draft.query(category, "inbox", [listTag]); // loop over found drafts looking for a matching list let d; for (let draft of drafts) { if (draft.content.startsWith("## " + category)) { d = draft; } } // if we didn't find the list, create it... if (!d) { d = Draft.create(); d.content = "## " + category + "\n\n"; } // tag and update content d.addTag(listTag); d.addTag("review-list"); let s = currentContent.split('\n') .map(ln => `- [ ] ${ln.trim()}`) .join('\n');; d.content = d.content + s + "\n" d.update(); } else { // user cancelled prompt context.cancel(); }
Options
-
After Success Trash Notification Info Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.