01-18-2020, 08:28 PM
Marc Anthony wrote:
Assuming you have consistently formatted documents, this returns paths hit by your search term and the text from the following paragraph.
set searchTerm to (display dialogInput the search string:default answerenergy management)'s text returned
set itsPathandpostPara to {}
set found to (do shell scriptfgrep -irA1& searchTerm's quoted form & space & (choose folder with promptLocate the folder containing the files to be searched.)'s POSIX path's quoted form)
set text item delimiters to-repeat with focus from 2 to (count found's paragraphs) by 3
set itsPathandpostPara's end to {found's paragraph focus's text item 1, found's paragraph focus's text item 2} & return
end repeat
set text item delimiters to return
set itsPathandpostPara to itsPathandpostPara as text
set text item delimiters to itsPathandpostPara
Thanks Marc! The docs are consistently formatted unfortunately. I did run it from within Script Editor (didn't even realize that was still around) and it stopped at the shell script with a "non-zero status." I appreciate it though.