Mdfind and the apostrophe

command linesearchspotlight

In terminal if I type

mdfind -onlyin ~/"Desktop/Shows I Watch" "Bob"

I get the output

/Users/brendans/Desktop/Shows I Watch/Bob's Burgers

As I would expect. But if I try

mdfind -onlyin ~/"Desktop/Shows I Watch" "Bob's Burgers"

I get nothing. I've tried lots of different escape keys for the apostrophe, but they all return nothing.

Here's a list of everything I've tried:

mdfind -onlyin ~/"Desktop/Shows I Watch" "Bob\'s Burgers"
mdfind -onlyin ~/"Desktop/Shows I Watch" "Bob\''s Burgers"
mdfind -onlyin ~/"Desktop/Shows I Watch" "Bob''s Burgers"
mdfind -onlyin ~/"Desktop/Shows I Watch" "Bob\\'s Burgers"
mdfind -onlyin ~/"Desktop/Shows I Watch" "'Bob'\\''s Burgers'"

What am I missing here?!?

Best Answer

You need to escape the single apostrophe with a single backslash and do not quote the show name if it has an apostrophe, just escape any spaces with a single backslash too, as in the examples below:

$ mdfind -onlyin ~/Desktop/"Shows I Watch" Bob\'s\ Burgers
/Users/name/Desktop/Shows I Watch/Bob's Burgers
$ mdfind -onlyin ~/Desktop/Shows\ I\ Watch Bob\'s\ Burgers
/Users/name/Desktop/Shows I Watch/Bob's Burgers
$ 

It should actually work with the show name in quotes as in the first example you have under "Here's a list of everything I've tried:", it worked on my system.

$ mdfind -onlyin ~/"Desktop/Shows I Watch" "Bob\'s Burgers"
/Users/name/Desktop/Shows I Watch/Bob's Burgers
$