MACRO: Spotlight Search Prompt

This should work for you, for now.

Spotlight Search Prompt Resources.pkg.zip (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.

##Changes:

  • 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 v1.0.zip 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.

Thanks!

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.

You're right, there is a bug, but I think there's a better solution. Use this instead:

  • Instead of checking "HTML Result Button" for "Cancel", check "sspResultButton".
  • Remove the check for "sspResult" being empty (as you've already done).

I believe this will solve the entire issue. If you look a the code for where "sspResultButton" is set, you'll see it gets set to "Cancel" if there is no value in "HTML Result Button" - which is what happens if you press Escape or ⌘+.

I hope this makes sense. Let me know if you understand, and if it solves your problem.

And thanks for reporting this issue!

Your fix worked fine and now the Spotlight Search Prompt sub-macro exits in the correct way for every possible case.

Thanks again for your macro and your assistance!

1 Like

Done for the next version (although not as thoroughly as @DanThomas’s macro).

6 Likes

Wait so KM will have its own native spotlight search prompt in next version?

No, it will have a native version of what @DanThomas’s macro does, it let you select from a list with a spotlight-like interface. Similar to the Add Action by Name interface, but with your supplied data.

1 Like

That would be amazing. As currently Dan Thomas’s macro is amazing as it is but it has a rather annoying startup delay. Since I use this macro very often, a native solution would be so great.

Thank you @peternlewis

Dan, your original post at top is still at Ver 1.0. Did you ever make an official update to Ver 1.1?

I have made a number of mods to whatever version I had, which I assume is/was Ver 1.0. How can I tell for sure?

Nope, I never released another version. And on my computer, at least, the macro “Spotlight Search Prompt” says what version it is.

I would like to dynamically create a palette (or some sort of search/selection interface) based on the contents of a specified folder. I've begun looking at Spotlight Search Prompt as a solution.

Am I on the right track, below? I think the plan would be...

  • Get the contents of the specified folder using For Each Path in Folder.
  • Get the Path of each item in the specified folder and append to sspData variable.
  • Get the base name of the file, or the last path component if the item is a folder, as a separate field to search on and select from. (Might be nice if the full path were even part of the search.)

If this is a good plan?

If so, I have a question: How do I get the data in the sspData variable formatted properly so that the item names are what is searched but the path for the selected item is the result...so that I can have KM maestro open that path?

Take a look at the example macros that @DanThomas provided in the Spotlight Search Prompt Macro Group (installed when you import Dan's macro). I found the examples/instructions very clear and helpful.

image

1 Like

Yes! Thank you! Example 2 will provide a good start. The path takes the place of the ID#. The item name takes the place of the Name. Thanks!

1 Like

I have a feature request to this amazing macro.

I want to display two fields. Is it possible to customize the jsonDisplayField to display two fields, just like the jsonStatusLineFields?

I am using these amazing prompts to insert references to Scrivener.

Do you mean like two columns in the list of choices?
aka, a table. :wink:

I have a similar need, and asked Dan about it, and he said he didn't have any handy solutions.
So, my workaround is to display them in "text columns", using a separator like the vertical bar (|).
Here's a screenshot from my script handler macro:

I use a script to build the input stream, and RegEx to parse the selected results.
I'd share the script with you but it is highly specific to, and embedded in, the acquisition of the source data from my script library. When I get a chance tomorrow, I'll take a look, if you are interested, in extracting the part of the script that builds the text table.

Thank you. that will be nice.

Here's my script segment, which won't run as is, but should be a good guide to developing your own script:

use AppleScript version "2.5" -- El Capitan (10.11) or later
use framework "Foundation" -- this may not be required
use scripting additions

set divStr to " ∣ " -- this is NOT the std vertical bar (which won't work with SSP)


--- Get List of Handlers with Items for Name, Params, Tags --- #Satimage.osax
set handList to JMLib's satFind(reFindHandParts, handlerListStr, true)

(*
  RESULT in this format:  List of Lists, one main item per handler
  {{Handler1 full match, name, params, tags}, {Handler2 full match, name, params, tags}, ...}
*)
set AppleScript's text item delimiters to ""

set handTextTable to ""

--- Now Actually Build the Table ---

repeat with oHand in handList
  set hName to item 2 in oHand
  set hParams to item 3 in oHand
  set hTags to item 4 in oHand
  set handTextTable to handTextTable & padR(hName, namePad, " ") & ¬
    divStr & padR(hParams, paramsPad, " ") & ¬
    divStr & hTags & LF
end repeat

(*
    RESULT in this format:
    handlerName   ∣ optionalParam1, optionalParam2, ... ∣ @OptionalTextTag1 @OptionalTextTag2 ...
  *)

--- Header for Table ---
set tableHeaderStr to padR(handlerColTitle, namePad, " ") & ¬
  divStr & padR("PARAMETERS", paramsPad, " ") & ¬
  divStr & "TAGS" & LF & ¬
  padR("—", 115, "—")


--- Final Table ---
set handTextTable to tableHeaderStr & LF & handTextTable

--- OUTPUT Text Table to File ---
--    (overwrites existing file)

my writeStrToFile(handTextTable, handTextTablePath)

--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on padR(pSource, pTotalLen, pPadChars) -- @Strings @Pad
  -----------------------------------------------------------
  (*
  Ver: 1.2    2018-04-04
  PURPOSE:  Return String Padded RIGHT
  PARAMETERS:
    • pSource    : [text, number, or list item] Source data to be padded
    • pTotalLen  : [number]   Total length after padding
    • pPadChars  : [text]    One or more character to be used as pad
  METHOD:  ASObjC
  -----------------------------------------------------------
  *)
  
  set paddedStr to pSource as text
  set sourceLen to length of paddedStr
  
  if (sourceLen ≤ pTotalLen) then
    
    --- ADD PADDING ---
    set paddedStr to current application's NSString's stringWithString:(pSource as text)
    set paddedStr to paddedStr's stringByPaddingToLength:(pTotalLen) withString:pPadChars startingAtIndex:0
    
  else --- SOURCE IS GREATER THAN PAD LENGTH ---
    ###    set paddedStr to (text items 1 thru (pTotalLen - 1) of paddedStr) & "…"
    
  end if
  
  return paddedStr as text
  
end padR
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on writeStrToFile(pString, pPosixPath) --  @File @Write @ASObjC
  (*  VER: 1.1    2017-03-14
---------------------------------------------------------------------------------
  PURPOSE:  Output String to File
  PARAMETERS:
    • pString        | text  | String to be output to file
    • pPosixPath    | text  | POSIX path of file
  RETURNS:  true if successfull
  AUTHOR:  JMichaelTX based on script by Chris Stone (@ccstone)
  REQUIRES:
    1. macOS 10.10.5+
    2. use framework "Foundation"

—————————————————————————————————————————————————————————————————————————————————
*)
  set nsSourceString to current application's NSString's stringWithString:pString
  set nsPosixPath to (current application's NSString's stringWithString:pPosixPath)'s stringByExpandingTildeInPath
  
  nsSourceString's writeToFile:nsPosixPath atomically:true encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)
  # Other encodings: NSMacOSRomanStringEncoding
  
  return true
  
end writeStrToFile
--~~~~~~~~~~~~~~~ END OF handler writeStrToFile ~~~~~~~~~~~~~~~~~~~~~~~~~

In my case, I just used the simple SSP, like in Example 1.
So, I just load the KM sspData variable from file:
image

Good luck!

1 Like

I love the fact that I can control the size of the list and the size of the window.

One of the limiting problems I have with Typinator's Quick search is the size of the window. Longer abbreviations get truncated.

Thank you so much @DanThomas

1 Like