MACRO: Spotlight Search Prompt

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

@Jamag Well, one possible way of doing it would be to use a "custom button", which is explained when you launch the "Spotlight Search Prompt Documentation" macro. You could have a button that says "Add". Unfortunately, it won't return the value entered in the search field, but you could at least use it to run another macro that prompts you for the value, and adds it to your list.

Can't live without this every day now.

1 Like

Hey Alx,

Then you should take a good look at Dan's Killer-Macro KMFAM as well.  :sunglasses:

MACRO: [KMFAM] Favorite Actions and Macros

-Chris

2 Likes

Thanks! I feel that way in general about Keyboard Maestro, but then, I suppose most of us feel that way. It's such an integral part of my everyday workflow that I can't even imagine life without it!

3 Likes

Thanks, Chris. Honestly, I use it so often that I sometimes forget that I wrote it! You know you created something good when you even impress yourself! :smile:

1 Like

Either that, or you have the onset of Alzheimer's. :wink:

Just kidding, of course. I too use it many times a day, and often recommend it.

1 Like

Installed the macro carefully following the instructions.

Got an "Open URL failed with URL" error message after running "Spotlight Search Prompt".

What have I done wrong?

OSX version: Mac OS X 10.12.6.
Ressource Package file was moved to ~/Documents

I'm gathering you solved this issue?

Nope. That is why I am asking the question :grinning:

I assume you mean you got the error when running the Spotlight Search Prompt Documentation macro (You don't run the Spotlight Search Prompt macro by itself).

Try running this macro first: Spotlight KM Variables. It'll finish in an instant and won't display anything. Then run the Spotlight Search Prompt Documentation macro, and it should work OK. I hope.

When I click on the try button in Keyboard Maestro with the KM Variables macro, a "KM Variables" window is displayed.

When, right after this, I run the macro Spotlight Search Prompt Documentation, I still get the same URL error.