Spotlight General Purpose Search (macOS)

Spotlight is a powerful search tool, but it is sometimes difficult to remember the syntax to better define, or better limit, your search. This macro makes it easy to quickly build a more complex search when you need it.

Here's a screenshot of the Spotlight Input Form:


updated 2018-02-28 10:38 GMT-0600

MACRO:   @SL Mac Spotlight Std Search

~~~ VER: 2.0    2018-02-28 ~~~
• Rewrote sections to use Switch statement
• Other optimizations

DOWNLOAD:

@SL Mac Spotlight Std Search.kmmacros (77 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.


ReleaseNotes

Author: @JMichaelTX

PURPOSE: Provide a easy-to-use, flexible input to Spotlight Search

HOW TO USE:
(1) Press the HotKey from any app to activate
(2) Enter the Search Terms (defaults to last execution)
(3) Adjust, if needed, in the Spotlight box

WHAT IT DOES:
(1) Prompts the user for 3 Spotlight search terms:
• Name -- text in the name of the file
• Date
• Created or Modified
• Pre-define date ranges (Today, Last 7 days, Last 30 days, Last Year)
• Optional Custom range
• Kind -- The file kind or type (like PDF, Excel, Word, Folder, etc)
(2) Builds the Search terms from user input, opens Spotlight box or Finder Window, and pastes in the search text.

INSTALLATION/SETUP:
(1) Set the SLOpenInFinder variable to open in either Spotlight box or Finder window


image

4 Likes

Hey JM,

Click on it to make it pop-out and again to enlarge it.

-Chris

Thanks. I finally figured that out.

But why is the image so small this time?
Is it something I did, or has the forum changed?
The current size is too small to be readable, to be useful. So it’s just a waste of space. If it can’t be displayed at a readable size, seems to me that it should just show a small icon to click on to enlarge.

I have uploaded a revision to the macro, Ver 1.1.
This version ADDS an option to the user input form to select output to the normal Spotlight Search box, or to a Finder window.

Hey JM,

Thanks for this rich macro: adopted :smile:

As French I have to change the date format: Today 08/07/2015 ➞ 07/08/2015

To be more generic (for its international career :wink: ) perhaps an automated configuration based on system localization.

I also simplified the Russian doll if action Date range in sequential one and then easily customized with adds of "Today" and "Yesterday".

Adds also more focused extensions as ".txt" ".applescript" in list "Kind" (a test avoid use of keyword "kind:").

Alain

PS: What software have you used for the composite menu screen shot [1]?

The first click shows it all on the window, the second click shows it at full size. That seems a reasonable sequence to me in general. Clearly, for a very large image like this, the first click, all on the window probably wont work for a macro, but it would work fine for an image without text in it.

I agree. I just didn’t know how to do that.

If you, or anyone, knows how to specify the date format that uses the user’s local settings, I’d be glad to revise the macro to use it.

A line of AppleScript can be a solution, e.g.:

set mydate to short date string of ((current date) - 2 * days)

PS: What software have you used to make the composite menu screen shot [1]:

Snagit is what I have used for years, with both Mac and Windows, to do all of my screen capture and annotations. I highly recommend it. It’s also useful for quick videos to demo app behavior.

Thanks JM I will give a try.
– Alain

Beautiful (and impressive) macro! I noticed one key bug (I'm using MacOS 10.13.3 with KM 8.1.1; both are the latest versions as of the date of this post):

When I specify "None" in the SLKind field, it works fine. Here I've created and searched for some test documents containing "foox" in the filename:

But when I specify a file type in SLKind, e.g., "PDF", it appends a period to the search term (see "name:foox." at upper right) which means, in the case pictured here, that it's searching for "foox." rather than "foox"; as a consequence, it doesn't return any results:

To get the search results, I need to manually delete the period:

Using "Microsoft Word Document" instead of "PDF" in SLKind creates the same issue.

Sorry, I am unable to reproduce your behavior. I see nothing in the macro that would append a period.

But I am running Sierra, as opposed to your High Sierra:
Keyboard Maestro 8.1.1 (8.1.1) on macOS 10.12.6.

image

image

You might check the KM Variable "SLSearchTerms" in the KM prefs:

image

Just posted an update to the OP.

Thanks for your reply. I checked this, and the extra period that shows up in the search box isn't present in SLSearchTerms (see screenshot below).

One other minor difference I've noticed on my system is that your instructions say, for the fields in which you aren't imposing a search restriction, that you can either leave them blank or enter "None." I've found that, if any are blank, the macro doesn't work -- all non-restrictive fields need to say "None." This is not an issue in practice, since once you've entered None you never need to do so again (unless you apply a restriction). So I only mention it in case it gives another clue about what might be causing the divergent behavior on my system.

I also tried your new version of the Macro, and it doesn't work at all on my system (with either SLKind = PDF or SLKind = None).

So there's three possibilities for why I'm seeing different behavior from you:

  1. Different OS version
  2. Some difference in the way my system is configured, external to KM.
  3. Some internal conflict between your macro and one of my other KM macros (don't know enough about KM to know what that might be, or if such a conflict is even possible [since none of my other macros use the same trigger]).

Then the period is added when the KM macro is typing the SLSearchTerms text into the search box. Perhaps you have a maco that is being triggered, or a text expander, or even a macOS text substitution which is inserting the period.

Please double-check your System Preferences > Keyboard > Text to make sure "Add period with double-space" is unchecked:

image

Could you please more specific? Is the macro not executing, or exactly where does it fail?

1 Like

Yup that was it! I unchecked that and now everything is good (with the old macro).

1 Like

So if I run the new macro, I get a clunk sound followed immediately by the hero sound, and nothing is inserted into the Spotlight search field. Likewise, if I run the old macro, then delete what's in the Spotlight search field, same thing:

But if I first run the old macro, and then immediately run the new macro, rather than replacing the old search term with the new, it appends the new search term onto the old search term:

Alternately, if I first create the Spotlight search manually (instead of using your old macro), and then run your new macro, I observe the same appending behavior:

In other words, if the Spotlight field is blank, the new macro doesn't insert anything into that field. But if the Spotlight field has a previous query in it, it appends the new query to the old query.

Finally, the behavior I describe above is independent of whether I'm using SLKind=PDF or SLKind=None.

The "clunk" sound probably means something has failed. Did you notice an KM failure/error notifications?

You might need to increase the Pause time near the end of the macro:

image

My prior version has this set to 1 sec.

Increased it to 1.0 sec., didn’t see any error messages.

Also, I noticed that the first time I run the new macro after rebooting the computer, I only get a clunk. All subsequent executions give clunk+hero.

There is one way I can get the new macro to work: First, run a general Spotlight search (just enter something – doesn’t matter what–into the field next to the magnifying glass). I.e., I haven’t opened and filled the special subfields for restricted searches. Then run the new macro. What happens here is I get clunk+hero, after which it returns a correct search.

Maybe this is something that High Sierra broke. I just tested Ver 2.0 of my macro on another Mac running Sierra, and it works fine.

The macro does assume the following shortcuts for Spotlight searches:

  • ⌘SPACE for normal SL search
  • ⌃SPACE for Finder SL search

If you are really interested, you could step thru Ver 2 using the KM Debugger.

1 Like