Powerful Searches With Raw Query

You can search for files using the Raw Query function in the Finder. This gives you the ability to use wildcards to search for files with specific file names. You can also use other file attributes and combine them for even more complex searches. Raw Query is also very fast and can search your entire drive in seconds.

Video Transcript
Hi this is Gary with MacMost.com. On this episode let's take a look at how you can do powerful searches in the Finder using Raw Queries.

As an example here I've got some text files that I have created and put in a Samples folder in my Documents folder. So say I want to find one of these. Of course I can just use the basic search functionality here of the Search box at the top and type in the name. And I can even say I want it to be the Name Matching, not Contents. And it will find this file. I can specify that I want it in the current folder instead of the entire Mac. That all works really well.

But say I wanted to do something a little more complex. Like I wanted to find all files that ended with something or began with something or had certain characters in it. I want to basically use Wildcards that you might do in the more advanced system for searching for things.

But you can do that with the regular search if you know how.

So let's do something a little more complex. Say I wanted to find the file that ends with the letter Y. There is five out of seven here. So what I can do is I can start a search. I hit the spacebar here to start a search. I'm going to just search within that folder. I'm going to add search criteria here and I'm going to say, I can say the name ends with Y. You can see it works.

But what if I wanted to do something more even complex. What if I wanted something like the ones that have two p's in them or two e's in them. Well, I can't really do that with this very easily. I can do Contains and that will work. But I can't get even more complex than that. So I'm going to switch to, instead of searching by name, to search by Other and in this huge list of things you can search for, I can jump down to Raw Query. I'm going to search by Raw Query which I'm going to check off here so it appears now in the menu. So now it is easy to add.

With Raw Query I can search for things based on very specific things in the name. I have to use this special attribute. You have to list attributes. So kMD item display name then equals and I can do something like wildcard ppy, anything that ends in ppy or anything that has pp in the middle or ee in the middle or anything that has ee and then a z like that. You can use these asterisks any place you want in there to basically find files with very complex criteria of what is in the display name.

I can expand this beyond just that folder, of course, and look to see what is available on the entire drive. You can see there is a lot of different things here. This appears here because there are two ee's and there is a y there at the end.

So you can also see how quickly it searched the entire contents of my hard drive and there are a lot of files there. In addition, I don't have to just use this piece of criteria. I can use other ones. Like, for instance, here's one I'm going to put in called Duration Seconds and I'm going to make it greater than say 600 seconds. I get, returned, a whole bunch of things. Some of these are video files and some of these are audio files that have a duration of greater than 600 seconds.

You can combine things. So I can put parentheses around this. So video files that have that I have to use programmer notation here so this two ampersands is like asking and. So durations greater than 600 seconds and the display name is going to have, say, 2005 at the beginning of it. You can see now I only get results that have all of that going on in this much longer query here.

So probably the next thing you want to know is what else can you search for besides display name and duration of media. Well, if you look in the Apple Developer site you find a list of these Metadata Attributes. There are a ton of them here. The thing to worry about is that not all of them are you going to find.

For instance, just because there is one with copyright doesn't mean that you're file has a copyright date set to it. If you create something and you've created the file and you haven't to put a copyright date there it is not going to have it or the app you are using doesn't even use this.

So a lot of these aren't going to apply. But then a lot of them will apply universally for all files. So you kind of look through these and see ones that will apply to certain types of files, ones that will apply to all files, and ones that you may never see in any files that you are currently using. But at least it gives you an idea of what is available.

I'll include a link to this URL in the Notes for this episode.

Apple Spotlight Metadata Attributes page.

Comments: 17 Responses to “Powerful Searches With Raw Query”

    Rick
    6/29/15 @ 9:17 am

    Hi Gary,

    I want to thank you for your insightful and instructional videos. I have learned so much from your podcasts. I’ve been playing around with content searches within the finder but have yet to find what I’m looking for. I want to be able to search for lower case .jpg instead of .JPG and cannot seem to have finder differentiate the two.

    Have you found something that I’m missing in my search?

    Best
    Rick

      6/29/15 @ 3:23 pm

      This video is pretty much about exactly how to do what you want. Watch the video. Then use the Raw Query with:
      kMDItemDisplayName = *.jpg
      This will give you only the files with lowercase .jpg at the end.

        Rick
        7/7/15 @ 8:46 pm

        Thank you Gary. That worked!

    Lance
    7/2/15 @ 9:43 am

    Hi Gary, I tried this out and it’s really cool. I discovered that that the metadata attributes are completely case sensitive so I couldn’t just type in the metadata attribute. I had to make sure all the capitals were indeed capitals and then the search happened instantly. Thanks for this pretty geeky tool that is now at my fingertips.

    Nilesh Parmar
    7/2/15 @ 6:18 pm

    This is great for finder would this work in spotlight too?

      7/2/15 @ 7:02 pm

      This IS Spotlight. Finder searches are also referred to as spotlight searches. Perhaps you mean using the Spotlight menu instead of the Finder search window, at the top? You need to do this at the top of a Finder window since you have to specify “Raw Query” as I show.

    Furlan
    7/2/15 @ 6:52 pm

    Hi gary, thanks from Brazil! Could you post the URL?

      7/2/15 @ 7:00 pm

      Sorry. Forgot to post that. I just put a link above, under the video.

    Betty
    8/2/15 @ 4:22 am

    I had a hard time finding music to fit my movies. Thanks for this information. It has made my day!

    John Ford
    8/9/15 @ 6:04 am

    When I hit space bar in search I get a minus not a plus next to the ‘save’ button on the right. How do I add the additional search features?

      8/9/15 @ 7:23 am

      If you have no search modifiers in the list yet, you get a + button. Once you add your first, it is a – button, but a – and + button appear below it with the first modifier. Just use the + button there.

        Jeff Eichorst
        8/10/15 @ 5:47 am

        Hi Gary,
        I can’t seem to get the + to show up for anything. Whether I put something in the search window or not, I always have just a – next to the “save” button.
        Any suggestions?

    Rick
    8/21/15 @ 8:51 am

    Is there a way to limit the number of results displayed? If it yields say 1000 to 2000 at a time then I can actually rename or tag or move items.

      8/21/15 @ 8:54 am

      Depends on what you are doing. You limit the results by adding more conditions to the search, usually.

        Rick
        9/14/15 @ 10:36 am

        I want it to display 1000 to 2000 at a time such as an iTunes smart playlist.

          9/14/15 @ 10:46 am

          OK. But if you notice that when you create a smart playlist in iTunes, and you “Limit to” 1000 or 2000, you have to select criteria. The options are things like random, rating, artist, etc. So if you select by artist, for instance, you get the first 1000 songs when sorting by artist. So in the Finder you would do the same thing, just sort by filename or something else and then just only view the first 1000 and ignore the rest. I’m not sure of the utility of cutting off the list at 1000, though. In iTunes you do it to make syncing easier or only show you the songs you have rated highest — but in the Finder, what would that get you?

            Rick
            9/23/15 @ 10:22 am

            I would use this to tag original photos with Device_Date_Time_Original File Name.JPG for example. Tagging software become non responsive once I exceed 2000 photos at a time.

Comments Closed.