Jump to content
Conanap

Inline output for workflows

Recommended Posts

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

Share this post


Link to post

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

Share this post


Link to post

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!

Share this post


Link to post
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

Share this post


Link to post

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)?

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post

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.

Share this post


Link to post

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

Edited by Conanap

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...