1

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*"'
  • It's flaky - and not even based on file. For example if I replace 'thrill' with 'cheap' it finds the Sia 'Cheap Thrills' file. I guess I will try re-indexing spotlight and see what happens... – jmhindle Dec 5 '16 at 20:58
  • reindexing the spotlight database did not change the results. – jmhindle Dec 6 '16 at 18:16
  • 1
    Using the 'cd' modifier at the end of the string for kMDItemTitle corrected the problem. This is confusing because the 'd' command should just ignore diacriticals (i.e. accented characters matching non-accented equivalents). – jmhindle Jun 12 '17 at 13:46
1

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .