Title and Links no Longer Working

I’ve been using the Title and Links action for quite some time… Recently it stopped behaving properly and now not at all.

  1. Recently, it stopped updating the link in the currently open Draft.
  2. Last week, it never gave the prompt of complete after evaluating “x” number of drafts. I had to quit drafts, and the prompt was showing ion exit.
  3. Now, nothing is happening at all…

Is there any way to get this going again? - it is a critical partner action to wikilinks.


Quick update… in #3 nothing happening… it apparently did update the link on other Drafts — but the title of the currently selected draft was ignored and no pop up dialogue appeared.

Seems to be working fine here…what have you tried to troubleshoot? Is this specific to a certain draft/title? Have you tried with a test draft with different content? Tried re-installing the action?

Those are some next steps I’d look at.

These issues persist across all devices iPhone and iPad (both running the latest) and Macbook Air 12.6.2

In all instances, the machine becomes wonky - as if the CPU is overloaded… screen scroll lags, and navigation is thick.

I just reinstalled the action and ran it across a new note and it [a] did not update the linked file [b] did not rename the current draft [c] made the computer laggy +


While I was writing the above reply – Drafts gave the pop-up that it had evaluated 3,994 Drafts… ( so that’s good BUT took exceptionally longer than it used to – Machine is not running in a heavy state) but it only updated the current Draft title and not the [[linked Draft]]

Seems to be an either or…

Just ran it again over a workgroup and it took 28+ seconds to evaluate 375 Drafts.

This time all drafts and links were updated successfully.

Well, if you are running on that kind of corpus of data, this is a grossly inefficient action. You may just be running into legitimate performance issues.

This should really be written to only work with the drafts that will be effected by the change, and especially only update (e.g. create a database write) if a change occurs. Every time you run this action as it’s written it touching every one of those 3k+ drafts, re-saving it to the DB, force it to re-sync to the cloud and other devices - even if only a couple of drafts had references to the title in question.

Probably the best way to improve that is do change the query that generates the drafts like:

// replace this line...
// var drafts = app.currentWorkspace.query("all");

// with the below
let ws = app.currentWorkspace
ws.queryString = `"${oldLink}"`
let drafts = ws.query("all");

By doing that the drafts variable will only contain the drafts that have an exact text match for links to the old title, and you will only be looping over those matches.

I don’t have this issue, but I do use this action on occasion. Thanks @jaymf for posting here so others can learn and thanks @agiletortoise for posting a solution.

I updated my version of this action with your code fix to prevent this issue from happening to me.

This is an awesome community!

I’d like to suggest some additional revisions having dealt with identifying the wide variety of links in Drafts before in some of my own link management actions.

More Links

When working with a link, I believe these are all valid title-based links to the same draft:

  1. [[Master Plan]]
  2. [[d:Master Plan]]
  3. [[Master Plan/Step 1]]
  4. [[d:Master Plan/Step 1]]

Looking at the code in the original action, I appears it would only identify and update the first of these links.

let oldTitle = draft.displayTitle;
let oldLink = `[[${oldTitle}]]`;
d.content = d.content.replaceAll(oldLink, newLink);

Given this could actually cause a degredation of data, I think this would be a very worthwhile revision, anf perhaps one that @jaymf or @Mike_Burke would like to pick up as active users of the action? If the action does one replacement, it would just be a case of also doing other replacements.

I reckon you could do it with a modification to the value of oldLink and one alternative. Unless you want to go the regular expression route, in which case, I reckon just one replacement would be required :wink:

Further Query Constraints

The suggested workspace query searches only for the title text, so that is not impacted by the structure of the links discussed above, but it may still be pulling in more drafts to process than is strictly necessary. It would also pick up drafts containing the words of the title where they appear, but are not linked.

ws.queryString = `"${oldLink}"`

In most cases, for most people, I think this would be minimal overhead, but the reality is that it comes down to the original name of the draft and the previously spoken about draft volumes … hopefully it would not simply have been labelled “note” in amongst thousands of drafts about note taking :scream:

I’ll leave it to others to decide if it is worth the effort of narrowing things down in that search (it would make a good exercise of course), but the advanced query options do support options like Boolean operators and of course our favourite, regular expressions.

There may be other enhancements too. These points were just ones that occurred to me as I skimmed the thread and the code. Anyone up for taking a closer look and seeing if they can enhance and optimise things a little?

@agiletortoise thank you for helping diagnose the issue (I’m working on archiving unnecessary Drafts) and for the script change… works super fast now!!

1 Like

Totally agree @Mike_Burke — One of the best elements of Drafts is the amazing community!

@sylumer -

You illimuniate some critical points that I’m certain have fractured some of my links as I do use 3 of the 4 title variations you list here:

Unfortunately, I lack the ability to assist in optimizing the code of the script.

Happy to test though - if anyone would find it a useful exercise?

If you made Gregg’s suggested changes as you suggest that you have and you understnd that the lines I called out above set some variable values (the let lines) that are used to replace all such instances in the text (the replaceAll line), then I promise you have exactly enough ability to make the changes.

Do not sell yourself short on how much you have picked up through the various posts you have read and issues that have been resolved. I think you just haven’t put it into practice … yet.

Perhaps a little bit commenting/pseudo code would help?

// Let the new variable oldTitle be set equal to the title of the current draft withiout any Markdown heading syntax
let oldTitle = draft.displayTitle;

// Set the new variable oldLink be set equal to the oldTitle variable, wrapped in wiki-link brackets
let oldLink = `[[${oldTitle}]]`;

// Q) Could I clone that line to set another very similar variable as a variation with a slightly different type of link style?

// d is the existing variable representing a draft containing links that need updating
// Set the content of the draft to be updated to be the same except all instances of the value held in the oldLink variable should be replaced with the value of the values held in the newLink variable
d.content = d.content.replaceAll(oldLink, newLink);

// Q) What if I cloned that line, but chose variables that defined a variation of the link and did the replaces in succession like i might do a manual find and replace?
1 Like

Having given it a bit more thought, I’d like to retract this. Just two could fall afoul of another issue. I think, to be safe, it would need to be four static replacements … or one regular expression.

1 Like

Mighty kind of you to say and notice @sylumer. I appreciate learning from both you and Greg - a spectacular unexpected outcome of engaging here in this community.

That said, perhaps I have sold myself a bit short.

Will try to dig in harder and push my limits.

I thank you for the encouragement!