command line – How do I suppress warning messages for built-in terminal utilities (mdfind) in macos?


Ever since I upgraded to Sequoia – but I was quite late so this change may have come from an earlier macos – I am getting distracted by useless notifications from mdfind – the Spotlight command for the terminal.

sample command:

mdfind -onlyin . py

output:

(I want to do away with UserQueryParser noise)

2025-01-24 11:09:33.887 mdfind[71266:1628473] [UserQueryParser] Loading keywords and predicates for locale "en_US"
2025-01-24 11:09:33.888 mdfind[71266:1628473] [UserQueryParser] Loading keywords and predicates for locale "en"
/Users/me/kds2/wk/explore/test_522_nestedpprint.py
/Users/me/kds2/wk/explore/test_519c_so.py
/Users/me/kds2/wk/explore/test_nose/__init__.py
__init__.py

What I tried:

  1. I looked for a -q (quiet) option for mdfind’s arguments but there isn’t one.

  2. 2>/dev/null works but is annoying to put everywhere, even if I can alias it. Worse, I have some python scripts that call mdfind and I don’t want to suppress valid errors.

  3. 32 bit – How to suppress alert ‘this app is not optimized for your Mac’ is exactly what I want, however that seems specific both to GUI apps and a particular warning at that. But if I knew which default to write to, that would work very well.

  4. I could also | egrep -v UserQueryParser to filter it out, but it’s a bit like #3, annoying to do everywhere.

I’ve seen a few programs and utilities on Linux that also insist on mind-numbingly telling you about their particular grievances each and every time they are run, so I wonder what the general approach is to unclutter the command line noise a bit in general on these things. But this question is about mdfind.


update from trying something on basis of one answer:

I like the answer, but just wanted to make it more generic by using $@ to pick up all arguments.

jmdfindq () {
    #just pass all the args to mdfind and let it figure things out...
    mdfind "$@" 2>&1 | grep -v UserQueryParser
}

Strangely, it works sometimes

jmdfindq -name foo

(bme312) me@Mac explore % 
/System/Library/Frameworks/NotificationCenter.framework/Versions/A/Resources/Base.lproj/NCWidgetListFooterView.nib
/System/Library/Frameworks/NotificationCenter.framework/Versions/A/Resources/NCWidgetListFooterView.loctabl

but not others

jmdfindq -onlyin .

mdfind: no query specified.

Usage: mdfind [-live] [-count] [-onlyin directory] [-name fileName | -s smartFolderName | query]
list the files matching the query
query can be an expression or a sequence of words

OK, I get it. mdfind -onlyin . also complains because mdfind knows only that it has to be limited to current directory, but considers it still has no query.

jmdfindq -onlyin . py works just fine.

/Users/me/kds2/wk/explore/test_522_nestedpprint.py
/Users/me/kds2/wk/explore/test_519c_so.py

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img