Need Help to parse JSON Values out of sspData in a "Spotlight Search Prompt" based Macro

This is a Topic about a Macro which requires knowlege about Dan's Spotlight Search Prompt

Hello Folks, hello Dan (@DanThomas) ,

How Can I get any Key/Value pair/array or all at once for editing using JXA and how do I have to prepare the "Edit" Button for it?

The JSON-Code below is one Entry (Array) of my sspData-JSON

		"Topic_Name": "Easily Create Conflict Palettes - Then Run or Edit the Underlying Macros",
		"Topic_URL": "",
		"KMF_Category": "Tips & Tutorials",
		"Author": "@_jims (Jim Sauer)",
		"Keywords": [
			"@run or edit",
		"KMF_Tags": [

These are the current sspOptions which i've set for the Macro.
They are set to return only the URL for a Topic when I press ok

title: [@KMF] Keyboard Maestro Discourse —> Topics (Spotlight)
placeholder: Try something like “SSP“ or “Best Macro List“

dataType: json

jsonDisplayField: Topic_Name
jsonReturnField: Topic_URL
jsonStatusLineFields: KMF_Category, Author
jsonAdditionalSearchFields: KMF_Category, Author, Keywords, KMF_Tags
jsonStatusLineFunction: %Variable%sspStatusLineFunction%

customPromptWidth: %Variable%ssp__Width%
customPickListSize: %Variable%ssp__PickList Size%

customButtonEnabledWithoutSelection: true
cancelMacroIfCancelClicked: true

It would be nice If you could try help me out without asking for the full code.

Greetings from Germany


I need more information. Can you tell me exactly what you're trying to accomplish?

And I can't run your example, because 1) I don't know the values for the variables you're using, and 2) You didn't supply all the required parameters, like "customButtonText" and other values.

Damn, I knew I forgot something... thanks for reminding me on that, Dan.

My Macro is based on your Execute Macro by Name Version 1.2 with the Option embnShowEditButton enabled.

The other Parameters are

  • customButtonText: Edit (default of the Template-Macro)
  • %Variable%ssp__PickList Size%: 25
  • %Variable%ssp__Width%: in my case 1100 due to some very long Topicnames
  • %Variable%sspStatusLineFunction%: codeblock below
function(fieldValues) {
	if (!fieldValues)
		return "";

	var result = "KM-Discourse: " + fieldValues.KMF_Category;
	if (fieldValues.Author) {
		result = result + ", " + fieldValues.Author;
	return result;

My Goal is to edit the supplied Sub-Macros or open and edit the JSON File when no Selection is made and otherwise to edit the corresponding JSON array if I made a selection.

Since this is the first time I need to accomplish something like that, I hope there are all Infos you need to have now.

let me know if there is still something missing for you.

I'll try my very best. to give you all the Infos you need.

Greetings from Germany


Looking at this Forum post from Peter:

I cobbled this together. Let me know if it helps:

Find JSON Entry.kmmacros (4.8 KB)

1 Like

Thank you, Dan for providing this ...

I Installed the Macro - but I have to play with it and have to read and understand what is going on ....

Will come back on this...

Greetings from Germany


1 Like

Hello Dan,

sorry for the late reply - had some very bad headache ....

First of all - I like your Example Code.

I use your Code in my Macro but I don't get the array back if I make a selection in my Spotlight Search Prompt and hit on the Edit Button.

here are my changes I made due to my naming conventions:

  • Local_Json ==> Local__JSON
  • Local_SelectedURL ==> Local__selected_KMF_TopicURL
  • Local_Index ==> Local__JSON_Index
  • JSONVALUE(Local_Json[0]) ==> JSONVALUE(Local__JSON[0])
  • %JSONValue%Local_Json[Local_Index].Topic_URL% ==> %JSONValue%Local__JSON[Local__JSON_Index].Topic_URL%

This is the result in KM in my Macro:

What is missing here ?

  • The Variable sspData is read from a File and parsed without an error
  • The Variable sspResult is not empty

Do I have to find the URL of the selection in the JSON first before I can parse the Array?

  • If the answer is yes - How do I have to do this???

Greetings from Germany


That's what the "IF" action is supposed to be doing.

Try adding some Prompts and display the various fields that are being used, to make sure they contain what you think they do. For example, before the "IF" action, display what's in the text part of the IF, and also what's in the "is" portion.

Done. Here a screenshot:

The Variable sspData returns as "empty" this means Local__JSON - which should be the same - is empty, too.

I think the problem here is clear. Your Spotlight Search Prompt Macro seems to delete sspData. - That is not bad at all ... Only i n my Usage case since I need sspData after the Spotlight Search Prompt has done its Magic.

My Idea to fix this could be:

  • providing a Variable Local__sspData with the Value %Variable%sspData%
  • set Local__JSON to Value %Variable%Local__sspData%

What do you think about that ?

Greetings from Germany


I'm afraid I'm going to have to leave you to figure this out by yourself. I'm sorry, but I can see where this is leading, and it's taking more of my time than I can spare on this. Good luck!

Dan there is light in the dark...

My Idea was absolutely right.

But the thing is now that the code you provided parses only the very first URL

It would be nice if you you could provide me some example code which iterates through a growing JSON to find a URL.

Greetings from Germany


Just let the loop continue until it finds a match.

Thanks for mentioning that, Dan

It took time like forever for my somewhat "sometimes I am an Idiot" Head I have on my neck these days to figure out what the heck I was doing using your example code.

As I sometimes do the same like you are doing when developing Macros - using the Prompt for User Input Action to show results - I did NOT place it outside the For Each Action what caused the code to only parse me the very First URL.

Just edited the Macro moving the Action out there - It is working like it is supposed to !!
I'm now getting every array parsed out of my currently more than 130.

Thanks again for providing the example Code.

Greetings from Germany


1 Like