Replace Shortcut

I’m trying to get a shortcut to work as a search and replace across all drafts in a workspace.

The basic structure is the same as that used in the shortcut Greg provided: Workspace Summary.

I have substituted the "Replace with each item in… action for the actions Greg uses.

  • Get Drafts from <. > folder of workspace < > (one of the Drafts actions)
  • Repeat with each item in <. > (one of the Scripting actions)
    • Replace < >with <. > in < > (one of the Documents actions)
  • End Repeat

I had no luck with this. I tried as many variations with the Repeat action as I could think of. None resulted in a successful replacement - actually in no action at all. No error, and no modification to a draft - the shortcut completes but nothing happens.

I was able to substitute other actions for the Replace action and they worked, so I am pretty sure that the problem is with how I am using the five possible entries in the Replace action:

Replace < > with < > in < > and two switches.

The first switch is for case matching and the second for using regex. I’ve turned both off – I’m not trying anything fancy, just replacing one string with another.

I’ve tried various delimiters for the existing string and the replacement string. I’ve tried “Drafts” and “Repeat item” for the third parameter in the Replace action. Nothing I’ve tried works.

Any help in making this work would be appreciated.

Can you share what you have? We’re working practically blind without it.

Useful things to share are:

  1. The action.
  2. A simple, example set of draft content.
  3. Details of any user inputs.

Just one blind question, are you using draft.update() or similar at any point?

This is the shortcut that I’m using:

I’m not using draft.update(). There is an action labeled “Update Draft” in Shortcuts.

When you add it, there are two parameters: < > Draft < >. The first parameter requires a choice of “Replace”, “Append” or “Prepend.” The second parameter requires a specific draft - I don’t see a way to use it with “Repeat Action.”

I’m using a set of about a half dozen drafts in a test workspace. I’m trying very simple string replacements. For example, I might add lines with “abc” in several of the drafts in that workspace and try to replace “abc” with “def”.

My eventual goal is to be able to replace both a draft title and any links dependent upon the title elsewhere in a workspace.

Sorry, I’d figured for a find & replace you would be scripting it inside a Drafts action and rather than it actually being a Shortcuts shortcut; a bit of a long way around is all.

But the equivalent looks to be true. You are putting Drafts objects into Shortcuts and then not updating the drafts themselves.

You want to have the update draft acton in your shortcut replace the content of the draft being processed. That is the content that is produced as the result of the replace with action, assuming you switch it to operate on the content of the draft repeat item rather than the default attribute, which looks to be the title. The item to update is the repeat item (draft object).

Something like this -

Hope that gets you going again.

Note, you can get rid of the show action later. I put it in to show you how you can check the content is being replaced

1 Like

Thank you. Works great and is exactly what I was looking for.