Is the case insensitive comparison broken for mdfind

spotlightterminal

I use mdls and mdfind within scripts to automate playing music files. Recently I've noticed certain files missing from the expected search results and I have tracked it down to a case senstivity issue.

I'm using query syntax similar to kMDItemTitle == '*[search term]*'c. The trailing 'c' character used to provide a case-insensitive search.

Online documentation offers kMDItemTitle ==[c] '*[search term]* as a possibility, but that also fails to work.

Here are some exmaples from my command line:

⇒ mdfind -onlyin . 'kMDItemContentTypeTree == "public.audio" && kMDItemTitle == "*Thrill*"'
./Music/Sia/Cheap Thrills (feat. Sean Paul) - Single/01 Cheap Thrills (feat. Sean Paul).m4a
./Music/Michael Jackson/Thriller [Bonus Tracks]/17 Voice-Over Session from Thriller.m4a
./Music/Michael Jackson/Thriller [Bonus Tracks]/04 Thriller.m4a
./Music/J.J. Cale/The Road to Escondido/08 Hard to Thrill.m4a

⇒ mdfind -onlyin . 'kMDItemContentTypeTree == "public.audio" && kMDItemTitle == "*thrill*"c'

⇒ mdfind -onlyin . 'kMDItemContentTypeTree == "public.audio" && kMDItemTitle == "*THRILL*"c'

⇒ mdfind -onlyin . 'kMDItemContentTypeTree == "public.audio" && kMDItemTitle ==[c] "*THRILL*"'

Best Answer

It's working for me (Sierra). Specifically, the form you're used to works:

$ mdfind -onlyin . 'kMDItemContentTypeTree == "public.audio" && kMDItemTitle == "*ciao*"'c
...[non-album tracks]/Bella ciao.mp3
...Unreleased/Bella Ciao.mp3

I had no luck with the other form (... "==[c] ... "). The docs you linked to were from 2011; I found references from 2014 that use "your" form so it looks like the online docs are old and wrong! Unfortunately this suggests there's something wrong with your system, rather that with your queries. Sorry, I'm not sure what the next step would be.