How to Pause a Shell Script and Wait for User Input?

Howdy folks, I am trying to build a macro similar to my Use Dict (Homebrew Package) to Get a Word’s Definition macro, but to look up the word's synonyms using cli-thesaurus.

But for many words that have multiple meanings, the first result of the shell script is verification of which meaning you would like to use to look for synonyms. For instance, the word "well" can be an adjetive meaning "good", or a noun meaning "a source of water"... and you have to select the appropriate word to lookup. Running this in Terminal therefore produces this result:

Screenshot: list of words (click to expand/collapse)

Once you select an option, it will produce this, which is the desired end result:

Screenshot: list of synonyms (click to expand/collapse)

But when running this from Keyboard Maestro, it returns the following error:

Screenshot: error (click to expand/collapse)

Obviously, the shell script needs further user input before it can supply a list of synonyms, but I'm not sure how to accomplish that via a KM run shell script. So is there anyway to have the shell script output the list of words (screenshot 1) to a variable or clipboard so I can populate a prompt user from list, and then use the selection to finish executing the shell script?

The macro I am working on is below if anybody needs/wants to take a look at it.


01)Scratchpad.kmmacros (8.8 KB)

Macro screenshot (click to expand/collapse)

Since I'm just waking up now, my response will be short. The first thing I would do is run the program once, sending it a value of 1 as its input, and fetch all the results. Then I would display those results using KM. Then I would get the user's choice via a KM response. Then I would rerun the shell command a second time to give it the correct choice response, and process the output (last line?) to get the real value.

1 Like

I think you're on to something and have given me something to work with...

Modifying the shell script to use input from text, produces this result:

Screenshot (click to expand/collapse)

I bet I can use that to filter the lines between "Definitions" and "Select" to produce a list that I can then select from using the prompt with list action... thank you Sleepy! I'm gonna tinker with this later today! :grin:

Hey Sleepy, your idea worked out for me and I was able to make it happen. This is a VERY rough draft (that just uses the word "well" since it's still in development) and no doubt it can be greatly improved on, but at least I have it up and running. Thanks again for your help!

01)Scratchpad.kmmacros (12 KB)

Macro screenshot (click to expand/collapse)

Please deduct one from the number of favors that I owe you, since this worked.

1 Like

Haha I'm fairly certain you've helped me far more than I've helped you my friend. :grin: