Search for text string within file

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Re: Search for text string within file Tue Oct 10, 2023 8:48 am • by Mr_Noodle
It looks like the files are not being indexed by Spotlight. Can you check your Spotlight privacy settings?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Search for text string within file Tue Oct 10, 2023 9:10 am • by khardman
Ah....yes, I had set Spotlight to not search that folder in the Privacy settings.

I removed that folder to allow Spotlight to search, and I reindexed Spotlight.

Unfortunately, still no luck. I am receiving the same "Rule does not match" as before.
khardman
 
Posts: 17
Joined: Mon Oct 02, 2023 9:44 pm

Re: Search for text string within file Tue Oct 10, 2023 4:27 pm • by awaldraff
khardman wrote:What attribute are you using to search the Markdown files?

I am trying to search for a specific text string. I am using Contents | contains match | text value


You could use anything. But to give it structure I have been including YAML code on each file. I can then match any of the fields easily

See example

Code: Select all
---
category: articles
tags: strategy
jd: 1091.02 articulos
publishDate: 2023-05-12
---
author:: [[Michael E. Porter]]
URL:: https://hbr.org/1996/11/what-is-strategy
awaldraff
 
Posts: 32
Joined: Fri Sep 23, 2016 3:47 pm

Re: Search for text string within file Tue Oct 10, 2023 4:38 pm • by khardman
Thanks for the response. Can you share your Hazel search criteria?

All of my Markdown files have YAML headers like your example. My example is below. I am trying to find all files with "publish: true" in the Markdown header.

---
publish: true
filetype:
- archproject
pipeline:
- TKWA Active
---
khardman
 
Posts: 17
Joined: Mon Oct 02, 2023 9:44 pm

Re: Search for text string within file Wed Oct 11, 2023 8:39 am • by Mr_Noodle
Can you post the mdls output after fixing Spotlight?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Search for text string within file Wed Oct 11, 2023 10:10 am • by khardman
Here you go:

khardman@Kevins-MacBook-Air ~ % mdls /Users/khardman/Library/Mobile\ Documents/iCloud\~md\~obsidian/Documents/kevinOS/TKWA\ Dashboard/Projects/Friedman\ Alley.md
_kMDItemDisplayNameWithExtensions = "Friedman Alley.md"
kMDItemContentCreationDate = 2023-09-19 20:52:19 +0000
kMDItemContentCreationDate_Ranking = 2023-09-20 00:00:00 +0000
kMDItemContentModificationDate = 2023-09-26 15:27:33 +0000
kMDItemContentType = "net.daringfireball.markdown"
kMDItemContentTypeTree = (
"net.daringfireball.markdown",
"public.plain-text",
"public.text",
"public.data",
"public.item",
"public.content"
)
kMDItemDateAdded = 2023-09-20 12:17:40 +0000
kMDItemDisplayName = "Friedman Alley.md"
kMDItemDocumentIdentifier = 2380
kMDItemFSContentChangeDate = 2023-09-26 15:27:33 +0000
kMDItemFSCreationDate = 2023-09-19 20:52:19 +0000
kMDItemFSCreatorCode = ""
kMDItemFSFinderFlags = 0
kMDItemFSHasCustomIcon = (null)
kMDItemFSInvisible = 0
kMDItemFSIsExtensionHidden = 0
kMDItemFSIsStationery = (null)
kMDItemFSLabel = 0
kMDItemFSName = "Friedman Alley.md"
kMDItemFSNodeCount = (null)
kMDItemFSOwnerGroupID = 20
kMDItemFSOwnerUserID = 501
kMDItemFSSize = 261
kMDItemFSTypeCode = ""
kMDItemInterestingDate_Ranking = 2023-10-09 00:00:00 +0000
kMDItemKind = "Markdown Document"
kMDItemLastUsedDate = 2023-10-09 15:36:11 +0000
kMDItemLastUsedDate_Ranking = 2023-10-09 00:00:00 +0000
kMDItemLogicalSize = 261
kMDItemPhysicalSize = 4096
kMDItemUseCount = 1
kMDItemUsedDates = (
"2023-10-09 05:00:00 +0000"
)
khardman
 
Posts: 17
Joined: Mon Oct 02, 2023 9:44 pm

Re: Search for text string within file Thu Oct 12, 2023 8:57 am • by Mr_Noodle
Ok, so it's now being properly categorized. What does the text look like in Hazel's preview?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Search for text string within file Thu Oct 12, 2023 9:26 am • by khardman
(Sorry for being such a bloody neophyte. How do I post an image? Can I only post a screenshot image if it's hosted elsewhere?)

The rule is:

Contents | contain match | "publish: true"

When I run preview:

"Rule does not match" when I click red X to the right of the rule it says "Not Matched | Contents" There is no value to the right of "Contents"
khardman
 
Posts: 17
Joined: Mon Oct 02, 2023 9:44 pm

Re: Search for text string within file Fri Oct 13, 2023 9:41 am • by Mr_Noodle
I should have asked this in the beginning, but what version of Hazel are you running?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Search for text string within file Fri Oct 13, 2023 9:48 am • by khardman
5.2.2
khardman
 
Posts: 17
Joined: Mon Oct 02, 2023 9:44 pm

Re: Search for text string within file Mon Oct 16, 2023 3:39 am • by tarrybrad
Hi everyone, I've actually had a similar experience. Take some basic steps

Open up Hazel and select the folder you want to monitor.
Add a rule to the folder.
In the rule settings, under the conditions, select "Kind" and set it to "Text".
Next, add an action and select "Run Shell Script" or "Run Automator Workflow" depending on your preference and expertise.
In the script or workflow, you can use command-line tools like grep to search for specific text strings within files.

In my case, I was trying to search for specific keywords within PDF files using Hazel. After setting up the conditions and actions correctly, I found that it worked like a charm.
tarrybrad
 
Posts: 1
Joined: Mon Oct 16, 2023 3:23 am

Re: Search for text string within file Mon Oct 16, 2023 9:59 am • by Mr_Noodle
Not having problems with your sample markdown file here. Can you try the following?

- Try that file in a different folder.
- Try a plain text file in the same folder.

Report back with the results.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Search for text string within file Mon Oct 16, 2023 11:59 am • by khardman
Did the following:
-Duplicated markdown file and saved as a text file within the same directory
-Copied the entire directory to a new location (including the directory with the single created text file). Created a new rule pointed to this new location and to copy files to another location.

In both instances rule preview says "Rule does not match"

Thanks for taking the time on this. It feels like there's something systematic preventing Hazel from searching the directories.
khardman
 
Posts: 17
Joined: Mon Oct 02, 2023 9:44 pm

Re: Search for text string within file Tue Oct 17, 2023 9:14 am • by Mr_Noodle
Do no text files at all work or is it just that one?
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Previous

Return to Support