Scripting a Wordservice action to apply to multiple docs

I have a hundred+ markdown documents that I’d like edit with Wordservice (or Mac’s built-in “Substitute”) in order to convert all straight quotes to smart / curly quotes, and apostrophes too.

I’m not sure where to start, any pointers would be appreciated. Thank you!

You can script that, and I’d suggest to use JavaScript because of it’s support for regular expressions.
As long as you do not have programming code in your MD documents, the approach should be straight forward.
A regular expression replacement could look like this

Explanation: "([^"]*)" looks for an opening quote followed by anything not a quote and finally a quote. The “anything but a quote” part is captured in a group by the enclosing parenthesis. In the replacement string, $1 refers to that group so that ”$1“ encloses the stuff that was limited by straight quotes in curly ones now.

And you would not need Wordservice for that, since DT can run this perfectly itself. A JavaScript script would look like this

(() => {
  const app = Application("DEVONthink 3");
  const regex = /"([^"*])"/g;
  app.selectedRecords().forEach(r => {
    const txt = r.plainText();
    r.plainText = txt.replaceAll(regex, '”$1“')

You’d select the record(s) you want to modify and then run the script on them. How to install it in DT’s scripting directory is explained in the documentation.

WARNING This ist not tested at all. You should only run it on duplicates of your documents until you’re sure that it does what you want.

1 Like

On a side note: You can’t script a service.

1 Like

If I understood the OP correctly, they were talking about a program called “Wordservice”. Or maybe not?

Wordservice is made by DEVONtechnologies

Both WordService and CalcService are just the front ends to install the services. Once the apps are launched they don’t need to be launched again. The services operate independently of the apps.

Well, the app provides the services and is launched by the system of course, no additional stuff gets installed. But you don’t launch it on your own, the system handles this after choosing a service.