Conanap Posted January 14, 2020 Posted January 14, 2020 (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! Edited January 14, 2020 by Conanap Clarified language
Terminal Posted January 14, 2020 Posted January 14, 2020 (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. Edited January 14, 2020 by Terminal
Conanap Posted January 14, 2020 Author Posted January 14, 2020 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!
Terminal Posted January 14, 2020 Posted January 14, 2020 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
Conanap Posted January 14, 2020 Author Posted January 14, 2020 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)?
Terminal Posted January 14, 2020 Posted January 14, 2020 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.
Conanap Posted January 14, 2020 Author Posted January 14, 2020 Thanks! I'll explore that option for now and see what I can do. I appreciate your help!
Terminal Posted January 14, 2020 Posted January 14, 2020 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
Conanap Posted January 14, 2020 Author Posted January 14, 2020 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.
Conanap Posted January 14, 2020 Author Posted January 14, 2020 (edited) Is it possible to use a different variable instead of query for output (for copying to keyboard pipeline)? Edited January 14, 2020 by Conanap
deanishe Posted January 14, 2020 Posted January 14, 2020 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.
Conanap Posted January 16, 2020 Author Posted January 16, 2020 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
deanishe Posted January 16, 2020 Posted January 16, 2020 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.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now