Jump to content

How to parse script OUTPUT

Recommended Posts

I have a CLI command/script I run which performs an action. This works great with the "Run Script" item.


However, I want to be able to parse the response from that script into an Alfred Variable and print it. Currently the only thing I have found is to wrap conditions within the bash script and return different outputs ,which is very limited.

What I"d like to be able to do is regex parse or match on certain fields returned (such as the JSON body) and return just those matching fields.


This is NOT the same as script filter as I want to return them as a notification, I don't want to change the output within the command line, and I only want to execute teh script once based on the single variable/field input. How can I parse the results/response of a field? Is there a way to match a variable to a regex?

Link to comment

This is a trimmed down version of the reload script from my linkding Bookmarks workflow:

bookmarks=$(curl -s "${baseUrl}")

case "${bookmarks}" in
		echo -n "linkding server not found"
	*"Invalid token"*)
		echo -n "Invalid API Token"
		mkdir -p "${alfred_workflow_data}"
		echo -nE "${bookmarks}" > "${bookmarks_file}"
		echo -n "Bookmarks Updated"

The curl command is run and its output assigned to the "bookmarks" variable. I then use a case statement to perform different actions based on whether the output is empty, contains "Invalid token", or the asterisk which matches any other output.


Is something like that what you're looking for?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...