For some reason, all the notes I have in nvAlt that I’m looking to move into Drafts have hashtags at the bottom, likely from an effort to use 1Writer tags. I’m looking to convert these hashtags to Drafts tags. I found an action that will do this on a single draft link to action, but I’d like to run this on all the drafts in the inbox at once. I tried to edit the script, but my lack of JavaScript knowledge has made it difficult, just kind of copying/pasting from other actions that seem like they might do what I’m looking for. Anyway, I came up with this, which isn’t working but was as far as I could get. Any suggestions on what to try next? Thanks!
// Get all the tagged drafts in the inbox
var taggedDrafts = Draft.query("", "inbox");
// find tags in content
var re = /#[\w\d]+/g;
var tags = draft.content.match(re);
// tag drafts
for (var i=0; i<taggedDrafts.length; i++) {
for (tag in tags) {
draft.addTag(tags[tag].substring(1));
};
taggedDrafts[i].content;
taggedDrafts[i].update();
}
1 Like
If you use the original one I think (it looks like it works on the current draft) you should just be able to hold Select in a listing (e.g. your workspace inbox) to select all drafts, then select Operations, Run Action and select your action to run against each draft.
See https://getdrafts.com/drafts/ for details on managing drafts.
1 Like
Oh, good idea. I have tried to run actions in multiple drafts before and the actions never supported it, so I forgot about that option.
Ok, I couldn’t let this rest because I wanted to figure out how to do the JavaScript for looping over several drafts. This code works for me:
// This script builds on kjaymiller script to find hashtags inside drafts by looking not just at current draft, but all drafts in inbox. Original script: http://actions.getdrafts.com/a/1ME
// Get all the tagged drafts in the inbox
var taggedDrafts = Draft.query("", "inbox");
// find tags in content
var re = /#[\w\d]+/g;
// Tag drafts
for (var i=0; i<taggedDrafts.length; i++) {
var tags = taggedDrafts[i].content.match(re);
for (tag in tags) {
taggedDrafts[i].addTag(tags[tag].substring(1));
}
taggedDrafts[i].content;
taggedDrafts[i].update();
}
https://actions.getdrafts.com/a/1Q7