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.
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.
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.
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.
Do you mean like two columns in the list of choices?
aka, a table.
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.
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:
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.)