MACRO: Spotlight Search Prompt

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

My pleasure. :smile:

I keep coming back to SSP and finding more uses for it. It's so fast and efficient. So, a question:

Is there an option within the SSP framework to have what is typed in the prompt added to the searchable data list.

The idea is to type a term in and quickly find it in the list, but if it's not there, then add it to the list (and use it as the result).

Nope, sorry. You can, of course, write your own macro that prompts for a value and adds it to your list. I know it's not the same, but that's all I got. (Although it sounds like a good option, but I don't have the time to add it as a feature.)

I too would like that option. :+1:
If anyone implements it, please advise us here.

1 Like