MACRO: Spotlight Search Prompt

#MACRO: Spotlight Search Prompt

###NOTE: Do not double-click the package file "Spotlight Search Prompt Resources.pkg"
It won't hurt anything, but you'll get a very misleading error message. The error message will tell you that the file is corrupted. It's not corrupted. I shouldn't have used a package file to store resources. It doesn't hurt, but it's obviously confusing.

Please just move the package file somewhere, usually in your Documents folder or a subfolder. Then leave it as is. DO NOT DELETE IT.

It's clear that I made a poor decision to store resources in a package file. I'll work something out for future releases.

Requires OS/X Yosemite or later.

Please see the Installation Instructions, below

Spotlight Search (862.3 KB)

###Bring a Spotlight to all your pick lists!

Extremely easy to use, but offers a bunch of optional features, as well.

##Supports data in three different formats:


Keys/Values (aka Dictionaries):


##Searchable Keyword Fields:

Custom Title, Status Line, Help and Custom Buttons, Custom Window Sizes:

...and more! (I sound like an Infomercial.)


  • Detailed, annotated documentation.
  • 18 Example Macros and Online Help Macros, from simple to full-featured.
  • Backed by a Jasmine test suite comprised of over 50 automated tests.

##Installation Instructions:

  1. Download the attached .zip file.
  2. Extract the zipped files.
  3. Move the Resources Package file to a location of your choosing.
  4. Import the .kmmacros file.
  5. Run the macro "Spotlight Search Prompt Documentation".
  • It will ask you to locate the Resources Package file from step #3.
  1. That's it! Run through the Example macros, peruse the documentation, and have fun!


This is incredibly impressive. I have no idea how I can make use of these great prompts right now though. I hope someone will come with something really interesting.

Thank you for sharing it Dan.


Coming very, very soon. :smile:

1 Like

###Dan, first of all, this is a totally awesome, general purpose, search/picklist system! :thumbsup:
Thank you so much for developing and sharing!
I have already thought of dozens of uses.
BTW, if you would like a beta tester for project like this, I'd be glad to help.

Here are some thoughts/ideas you can consider (or feel free to ignore) that may (or may not) improve things:

  1. Make clear that this macro, "Spotlight Search Prompt", is a sub-macro, and is not intended to be run/triggered directly.
  2. Provide the instructions in a PDF file, rather than an HTML and multiple image files
  • The HTML file would not open using Chrome on my Mac running Yosemite 10.10.5, but it did open fine in Chrome 52.0.2743.116 (2743.116) on macOS 10.11.4.
  • PDFs are easily read by everyone
  • Makes it easier to update/distribute
  • Enables Evernote users like me to attach to an Evernote Note.
  1. Automate the location/selection of the "Spotlight Search Prompt Resources.pkg" file. Below is a script you can use (and/or modify) if you wish that does this:
  • It searches the users "Documents" folder, and all sub-folders for the file.
  • If it finds just one file, it uses it.
  • Otherwise it prompts the user to select.
  • I have found it to be very fast, even though I have thousands of files in my Documents folder.
  • If the script does not find just one file, you are no worse off than now: It prompts the user to locate it. If it does, the uses is restricted to select ONLY package files.
  • It is designed according to my script return method, but you can easily change it to set the KM Variable directly if that is what you want.

Again, many, many thanks, and please keep up the great work!

###Script to Locate Resources PKG

2016-08-14 22:00 CT (Sun)

  • Fixed bug in set cmdStr statement
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

property ptyScriptName : "Locate Resources PKG"
property ptyScriptVer : "1.0.1"
property ptyScriptDate : "2016-08-14"
property ptyScriptAuthor : "JMichaelTX"

PURPOSE:  Locate the "Spotlight Search Prompt Resources.pkg"
        required by the Spolight Search Prompt system

KM VARIABLES REQUIRED: (must be set before calling this script)
  • NONE
KM VARIABLES SET: (by this script)
  • NONE

  set folderToSearch to POSIX path of ((path to home folder as text) & "Documents")
  --set folderToSearch to POSIX path of (choose folder)
  set fileNameStr to "Spotlight Search Prompt Resources.pkg"
  set cmdStr to "mdfind -onlyin " & quoted form of folderToSearch ¬
    & " 'kMDItemFSName=\"" & fileNameStr & "\"'"
  set findResults to do shell script cmdStr -- CALL mdfind in SHELL SCRIPT
  --- CONVERT TEXT LIST TO AppleScript LIST ---
  set fileList to paragraphs of findResults
  set numFiles to (count of fileList)
  set resourcePath to ""
  if (numFiles = 1) then ### ONE FILE FOUND
    set resourcePath to item 1 of fileList as text
  else if (numFiles > 1) then ### MULTIPLE FILES FOUND
    set resourcePath to choose from list fileList ¬
      with title ¬
      "Select the MAIN Resources PKG" with prompt "Choose Location of MAIN Resources.pkg"
  else ### NO FILES FOUND
    set resourcePath to POSIX path of (choose file with prompt "Locate \"" & fileNameStr & "\"" of type "" default location (folderToSearch) ¬
      without showing package contents)
  end if
  set returnResults to resourcePath
  --~~~~~~~~~~~~~ END TRY ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on error errMsg number errNum
  if errNum = -128 then ## User Canceled
    set returnResults to "[USER_CANCELED]" & return & return ¬
      & "SCRIPT: " & ptyScriptName & "   Ver: " & ptyScriptVer
    set returnResults to "[ERROR]" & return & return ¬
      & "SCRIPT: " & ptyScriptName & "   Ver: " & ptyScriptVer & return ¬
      & "Error Number: " & errNum & return ¬
      & errMsg
  end if
end try

return returnResults

Count on it. Great timing, actually. I’ll be hitting you up soon.

Make clear that this macro, “Spotlight Search Prompt”, is a sub-macro, and is not intended to be run/triggered directly.

Excellent idea.

Provide the instructions in a PDF file, rather than an HTML and multiple image files

Generally I hate PDF files, but you make a good point. But I think if I hadn’t created the HTML file from MS Word, there wouldn’t have been a problem. I’ll have to think that one through.

Automate the location/selection of the “Spotlight Search Prompt Resources.pkg” file. Below is a script you can use (and/or modify) if you wish that does this:

This is an outstanding idea, and it’s something I wanted to do, but couldn’t think of a way to do it. Thanks!

I am working on a custom installation script scenario, and if I come up with one that works, this won’t be necessary (probably). But if I don’t succeed, or possibly even if I do, I will certainly use this.


1 Like

Why? I love them and use them all the time.

MS Word has a “save as PDF” feature that works great. I also use that a lot. Never had any issues.

Just updated script.

I am still under OS/X Yosemite :blush:

Get this error, running π Example 1: Simple list of Strings


OK, we may get a few more of these, but let’s hope not. If you want to work around them, I’m happy to tell you how.

  1. Find the file “Spotlight Search Prompt Resources.pkg”.

  2. Right-click on it, and pick “Show Package Contents”.

  3. Open the file “Spotlight Search Prompt.html” in a text editor of some kind.

  4. Find and replace this line:
    if (!line.trim() || line.startsWith("--")) return;
    if (!line.trim() || line.indexOf("--") === 0) return;

  5. Save the file.

If (when) we get more of these, we’ll follow these same basic steps, with #4 changed, of course.

The issue is that the version of JavaScript that Yosemite supports is missing a few JavaScript functions. I tried not to use any of them, but apparently I didn’t pay enough attention.

An unique edit and works like a charm: thanks for the reactive support of the author :smiley:


Happy to hear it! Thanks for the bug report.

@JMichaelTX - Can you test this macro on Yosemite, and double-check that the above issue is the only one? I’ll post an updated version, if you can verify for me.


Hi Dan, thanks for the unvaluable “framework”.

I have a feature request:
provide a new option to return the exact string typed in the search field when the user press the Custom Button (now you can specify a fixed string).


P.S. A keyboard shortcut for the Custom Button would be also much appreciated

LOL. I hope you meant “invaluable”. :smile:

[P]rovide a new option to return the exact string typed in the search field when the user press the Custom Button (now you can specify a fixed string)

I can do that. I’ll add a variable called “sspResultSearchText”, or something like that.

A keyboard shortcut for the Custom Button would be also much appreciated

I’m pretty sure that’s feasible. The docs say the default modifiers are Ctrl+Alt, which seems strange to me, but I guess it might make sense because you wouldn’t want to conflict with Cmd+C, etc. Are you OK with Ctrl+Alt+key?

Invaluable, definitely!
Apologies for my bad English and/or my aversion to spell checking :kissing_closed_eyes:

No problem for me with this combination. Probably the best solution would be to have the shortcut automatically generated with the first letter of the button name (e.g. button “New” shortcut ⌃⌥+N) but only if it’s not going to be the source of possible conflicts.

P.S. Since I already made some small customisations on your macro set, could you please specify the modified files/macros in case you want to post a new version? This way I can substitute the changed stuff without restarting from scratch.
Thanks again!

I’m going to follow KM’s standard for the regular Prompt action, which is to follow the button text with “/key” as in “/F” to specify the shortcut. Hope that’s OK.

Could you please specify the modified files/macros in case you want to post a new version?


I’m double-checking about the Ctrl+Alt modifiers. I should be able to make these changes relatively soon.

This should work for you, for now.

Spotlight Search Prompt (501.9 KB)

Unzip this file. Once you do, you'll have a new Resources package file. Remember, DO NOT DOUBLE-CLICK the .pkg file. :slight_smile:

Move or rename your existing resources package file, and put this new one where your old one was. Let me know if you have questions about this.

For these changes, the Macros themselves haven't changed.


  • Fixed issue that caused an error message under Yosemite, on some systems.

  • Redesigned the Help HTML file, because there were issues displaying it on some systems.

  • Added the ability to specify a keyboard shortcut for Custom Buttons. This works similar to the standard Keyboard Maestro "Prompt for User Input" action:

  • Specify the custom button text like this:

"customButtonText: Edit/E"

  • In this example, the keyboard shortcut for the "Edit" button will be Control+Option+E.

  • If you hover the mouse cursor over the custom button, a tooltip will show you the keyboard shortcut.

  • When the OK or Custom Button are clicked, whatever the user had currently typed in the Filter box will be returned in the variable "sspResultFilterText".

PS to anyone following along:

I’m not going to release version 1.1 yet, meaning I’m not going to replace the original file.

I have an upcoming project that I hope will help automate the process of updating existing macros and resources, and I’m hoping to use it to release v1.1.

@JMichaelTX -

I have a new HTML file. Can you see if this solves the problem you had? I completely redid this one. I used Markdown in Quiver, and exported it as HTML.

  • Grab the zip file from a couple of posts above.
  • Unzip the .pkg file
  • In Finder, “Show Package Contents”
  • Navigate to the “docs” folder.
  • Open “Spotlight Documentation.htm” in Safari and see if it displays OK.


Hi Dan,
thanks for taking the time to modify the resources files. Much appreciated.

I made a few changes on the If block at the end of the Spotlight Search Prompt sub-macro (the action that cancel the sub-macro if needed; see also attached screenshot).
Just want to inform you in case you think they could be added to you "master copy":

  1. Removed the condition sspResult is empty: using the Custom Button leaves that variable untouched (i.e. empty) so the cancellation was incorrectly triggered (that's a temporary workaround; see below)

  2. Added deletion of variables sspResult and sspResultButton in the "Cancel" branch of the block (so they're deleted when cancelling the sub-macro as well)

  3. Moved deletion of variable sspCancelMacroIfCancelClicked outside (after) the block so tha variable is deleted when pressing OK button as well

A glitch was introduced by the deletion of the sspResult is empty condition: when cancelling the prompt using the default shortcut ⌘+. the variable HTML Result Button is not set to "Cancel" so the cancellation in the If block is not triggered.
This could be avoided reintroducing the above mentioned condition but that requires the sspResult to be set to something like "(none)" when the prompt is closed using the Custom Button.