Jump to content

Inline output for workflows


Recommended Posts

Posted (edited)

Hello! I'm not sure what these were called so I had some trouble googling. I'm making a molar mass calculator and I want the output to look like the attachment.

 

Eg: molm H2O

 

 should then show in the next line "18.01528 g/mol"

 

I have the logic for figuring out the input and calculations, but I can't for the love of god figure out how to do the output like the photo. I'm using keyword to script with bash. Thanks!

 

Screen Shot 2020-01-13 at 5.23.00 PM.png

Edited by Conanap
Clarified language
Posted (edited)

You need to emit the output in a certain format in order For Alfred to recognize it and automatically insert it into its windows.

 

If you share what language you are writing it in, I will get an example for you.

 

The screen below will give you the results.

 

bIBpWWT.png

Edited by Terminal
Posted

I'm writing using bash and for some reason it couldn't recognize the variables, but I'll give JS / Python a try using your specified info. Thanks!

Posted
2 minutes ago, Conanap said:

I'm writing using bash and for some reason it couldn't recognize the variables, but I'll give JS / Python a try using your specified info. Thanks!

 

 

If using python Python Alfred Workflow Library; its a great library for writing Alfred workflows.

 

How are you referencing the variables in bash? They get set a Environment variables. So {var:title} becomes $title

Posted

Yup I'm referencing with $title, but it doesn't show; I did something like {"items":[ { "title":$title } ] } . I'll keep the Python library in mind, but rn since I'm just reading from a CSV file and adding numbers together I'll probably implement it in a bit.  

For Python though, I just need to do sys.stdout.write(json obj)?

Posted
Just now, Conanap said:

Yup I'm referencing with $title, but it doesn't show; I did something like {"items":[ { "title":$title } ] } . I'll keep the Python library in mind, but rn since I'm just reading from a CSV file and adding numbers together I'll probably implement it in a bit.  

For Python though, I just need to do sys.stdout.write(json obj)?

 

That is odd.

 

And yes, for python that call should work just fine.

Posted
11 minutes ago, Conanap said:

Thanks! I'll explore that option for now and see what I can do. I appreciate your help!

 

Just because I am curious minded. Maybe test this?

 

query="{\"items\":[{\"title\":\"$1\", \"subtitle\":\"$title\", \"arg\": \"HIJ\"}]}"

echo -n $query

VVMZUGI.png

 

7DZctCq.jpg

 

qe5k5q4.png

Posted

oh huh that worked! I didn't echo $query, maybe that's why? I just did the cat << EOB thing that they had in the example. Thank you! I'll use this template.

Posted (edited)

Is it possible to use a different variable instead of query for output (for copying to keyboard pipeline)?

Edited by Conanap
Posted
2 hours ago, Conanap said:

Is it possible to use a different variable instead of query for output (for copying to keyboard pipeline)?

 

What do you mean exactly? You set the variable $query yourself. You can call it whatever you want.

Posted
On 1/14/2020 at 3:27 PM, deanishe said:

 

What do you mean exactly? You set the variable $query yourself. You can call it whatever you want.

On earlier attempts of outputting variables other than query seemed to failed, and it continue to copy $query to clipboard anyways; I'll give it another try though

Posted
4 minutes ago, Conanap said:

On earlier attempts of outputting variables other than query seemed to failed, and it continue to copy $query to clipboard anyways; I'll give it another try though

 

I don't follow you. There is no variable called $query unless you create it.

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...