RegEx Find/Replace in e-Sword-X Notes Files

I have been assigned the task of looking through hundreds of random files on a Mac, locating certain items in each file with the regular expression:

(  [A-Z][a-z][a-z]( )[0-9]+:[0-9]+  )

Then manually, selecting each item (one at a time), executing a KM Macro on the selected item... then going to the next item in the file.

I cannot figure out how to get from searching on the above RegEx, selecting the item, then executing the KM Macro I built to change the item. I want to execute a KM Macro to change all of the items in a file and save it (Command S).

Thanks in advance!

Are you sure the RegEx is even working? It looks a little strange to me.

Hey Mark,

Welcome to the forum!   :smile:

Do you have a working macro? If so it would be best if you can post it, so we can see what you're doing.

How to Post Your Macro to the Forum

If you haven't read this it's worth a couple of minutes of your time.

Tip: How Do I Get The Best Answer in the Shortest Time?

You have not described your task sufficiently for us to comment.

  1. How are you finding your files in the first place?

  2. How are the files being displayed once found?

  3. You're locating files with the regex in the name or in the contents?

  4. You're changing the name or the contents?

  5. Please provide examples of the text you're finding with your regular expression.

Once we have more specifics we can offer better help.

And – not to be crass an any way – but until we have a sufficiently complete outline of your task it's not worth our time to comment.

The devil is in the details...

Looking forward to understanding the details of your task.


( [A-Z][a-z]a-z[0-9]+:[0-9]+ )[quote="MartinPacker, post:2, topic:21541"]
It looks a little strange to me.

Hey Martin,

Yes, Mark didn't know about code-fencing, and Discourse rendered his regular expression in peculiar fashion.

I fixed it in his post above, but here it is again:


( [A-Z][a-z]a-z[0-9]+:[0-9]+ )


( [A-Z][a-z][a-z]( )[0-9]+:[0-9]+ )


1 Like
  1. Sorry for the lack of information/description of the problem.

  2. This forum is fantastic! Thanks so much!

  3. Here is the Problem Macro
    Macro 6 - Search and Modifiy Reference.kmmacros (3.2 KB)

4.I just realized that the RegEx is not correct. That is why it is not finding the 2nd Reference. References can be either [A-Z][a-z]a-z[0-9]+:[0-9]+ or [0-9][a-z]a-z[0-9]+:[0-9]+

Example of File contents:
**Eph 4:2 **
We have not only changed our β€œminds,” we have totally changed our citizenship. We are part of a new creation. 2Co 5:17

  1. I manually locate Eph 4:24 in the document, select Eph 4:24, then I would do Option 2 (which executes "Macro 2" in the last step - see Problem Macro). Then I do the same for 2Co 5:17. Then I Command S to save the file.

  2. All of the files reside in a Bible software program called e-Sword-X. They are Notes attached to each verse in the Bible. Making changes to a Note (text file) is no different that making a change to any text file, except that e-Sword-X has Command J which can convert the reference to a link (to the verse)... Once converted, the references can be clicked to reveal a popup which displays the verse.

I hope this helps!

Hey Mark,

As far as I can make out you're using Keyboard Maestro to drive a find/replace process within the application e-Sword-X.

I looked at e-Sword-X ($10.00) on the app-store briefly, and without being able to use the actual app it's hard to imagine your workflow.

Are these notes files actually just text files? Or are they rich-text?

Can they be opened with an external editor?

How many find/replace operations are you actually doing?

You should probably post some screenshots.


If I understand your workflow correctly (and correct me if I don't), it looks like you have two major steps:

  1. Identify all files that meet some criteria (what is the criteria)?
    • I would probably use a Bash command in a KM Shell Script, to get the list of files to process. Might use either find or mdfind.
  2. For each of these files, change the contents of the file, replacing certain strings the meet some criteria (again, what is the criteria?) and replace with certain text (what is the text?)
    • This sounds like a typical find and replace, where you have a table of items to find, and then the corresponding text to replace.
    • KM can easily to a Regex Search and Replace on a file.

If these files are text files, then it does not matter what app you may sometimes use with them.

Please confirm or correct my statement of your workflow, and provide the requested criteria. And please provide a file, zipped, that is the table of text to find and replace.

That is the work flow exactly. However, I am not concerned at all with item 1 in your work flow above. My only concern is item 2.

I would like to find all of the scripture references in a file, select each reference, do a Command J on that selection and then move to the next scripture reference in the file, etc.

Here are two examples of the scripture references: Php 2:14 or 1Co 2:14. The first part before the space is always 3 characters. The first character could be AlphaNumeric. The second and third characters are always Alpha. The last portion of the reference could be 1:1 to 999:999.
Example: Psa 119:174 or Psa 99:9 etc. I tried to come up with a RegEx to find these, but it only found the Alpha ones. [A-Z][a-z][a-z]( )[0-9]+:[0-9]+ I hope this answers your request for a "table" of text to find and replace. I was hoping to come up with a RegEx to find all of these instead of creating a table with 100,000 possibilities.

Thanks for your help!

Here is a screenshot of one typical text file I just found:

I first noticed that there is already a link in this file (green color).
I also noticed that there are 14 other scripture references that I have to link.

Here is a screenshot of how I select the first scripture reference:

Now I do a Command J, which turns that scripture reference into a link (underlined):

Now, when I click on that link, I get the scripture reference in a pop up window (Exodus 9:8-11) 4 verses:

Then I go to the next one, select it, Command J and then it turns into a link which I can click on and get the scripture reference in a popup:

Again, I am not concerned about finding these files. I just want to be able to link all the references in a file, with one KM Macro.

Also, I was using a Regular Expression Editor and came up with this: (Which appears to pick up both styles of scripture reference.) It won't find the scripture reference when there is a range of verses. (Not sure how to do that in RegEx). Ex: Exe 9:8-11

So, can we use a KM Macro (version 9.2) to search the RegEx, select the reference, and do a Command J?


So once I saw "Eph 4:2" I realised it was a Bible reference. And I'm not surprised it would miss the cases where there was a Book Number at the front.

I'm thinking being more upfront about it being a biblical quote action you were building would've got others sharing what they'd done in this problem space.

(No, not being a bible a reader, I don't have any myself.)

Yes, but...
What does CMD-J do?
Are you using a specific app to search the text?
Where does the reference come from?

Your actual workflow is still very unclear.
It would be best if you could create a video, with narration, that shows you going through all steps.

Hey Mark,

You're actually doing the Find-Text part of this task with e-Sword – right?

⌘J is keystroke for a command in e-Sword – right?

In order for us to understand the workflow and make coherent suggestions we need to know the whole process, and you keep showing us pieces...


I was messing around with it this morning and got it working!!
Sorry about the very poor description of my work flow.

It's exciting to be able to use more of KM in automating my workflow. There are so many examples out there (which I took advantage of). They make it easier to put the macros together. KM is amazing!

Thanks for your help!


Great! And does Cmd+J have a menu item equivalent?

Please post your final macro that works so others can benefit.
See How to upload your macro. Instructions for uploading to an existing post are just below the main instruction.