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).
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
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.
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.
If I understand your workflow correctly (and correct me if I don't), it looks like you have two major steps:
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.
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.
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:
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 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.)
Chris,
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!
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.