Search for Text in File without relying on Spotlight Index

From your noodle to other noodles. Talk about ways to get the most from Hazel. Even exchange recipes for the cool rules you've thought up. DO NOT POST YOUR QUESTIONS HERE.

Moderators: Mr_Noodle, Moderators

There have been a number of users wondering how to search the text of a file (OCR'd documents, unusual extensions) whose metadata is not recorded in Spotlight.

Here is the 1-Step solution:

Step 1: Add Returns shell script condition to rule.

Code: Select all
exit $([ $(grep -ci "the text that you want to find" "$1") -gt 0 ])

This script will match a file (i.e. return 0) when text you want to find is found at least once within the text of the file being matched.

EDIT - enclosed $1 in quotes to prevent unescaped path errors.
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Return to Tips & Tricks - DO NOT POST QUESTIONS