Cliff Posted May 6, 2021 Posted May 6, 2021 I just want to enter "pfee 100" to get "3.2" entered into my clipboard (100 x 2.9% + 0.30) agh! Here's my 4min demo video of how/why it's not working if you could PLEASE help: https://share.getcloudapp.com/NQuwnnr2 And the start of my workflow is here: https://share.getcloudapp.com/llu5eeEE tyvm!
giovanni Posted May 7, 2021 Posted May 7, 2021 (edited) Hi @Cliff, you need to return a JSON or XML object. if you can use zsh (with input as argv) this below works #!/bin/zsh myVar=$(( $1 *0.029 +0.3)) myVar_f=$(printf "%.2g" $myVar) cat << EOB {"items": [ { "title": "your fee is $myVar_f", "subtitle": "your input was $1", "arg": $myVar_f } ]} EOB Edited May 12, 2021 by giovanni
Cliff Posted May 7, 2021 Author Posted May 7, 2021 @giovanni tyvm but is there any way to stick with PHP so I can be comfortable editing further and to learn for other snippets? In PHP, I tried both `return` and `echo` of JSON and it didn't work like your script did I want the result to pass through to the clipboard action so I can auto-paste
deanishe Posted May 7, 2021 Posted May 7, 2021 (edited) 5 hours ago, Cliff said: And the start of my workflow is here: https://share.getcloudapp.com/llu5eeEE You misunderstand how Alfred works. There is only one argument to your script, $argv[1], which contains everything the user entered. You’re using $argv[2] etc., which don’t exist. You also can’t just echo a result from a Script Filter. You must output JSON in the format expected by Alfred. Try this code instead: <?php $gross = $argv[1]; // user input $pct = 0.029; $flat = 0.3; $sum = $gross * $pct + $flat; // Alfred feedback JSON $item = array('title' => "$sum", 'arg' => "$sum"); $json = json_encode(array('items' => array($item))); echo $json; // send JSON to Alfred ?> Edited May 7, 2021 by deanishe
Cliff Posted May 7, 2021 Author Posted May 7, 2021 @deanishe thank you! It worked However, when I change it from "with input as argv" to "with input as {query}" (and changed your code to either $gross = {query}; or $gross = "{query}"; then it wouldn't work. Where is documentation for this? I didn't find these specifications at https://www.alfredapp.com/help/workflows/ For example, what else is available within the $argv array?
deanishe Posted May 8, 2021 Posted May 8, 2021 17 hours ago, Cliff said: However, when I change it from "with input as argv" to "with input as {query}" (and changed your code to either $gross = {query}; or $gross = "{query}"; then it wouldn't work. Then you've done something wrong. And you should almost always use "with input as argv", anyway. It works much better. 17 hours ago, Cliff said: For example, what else is available within the $argv array? Nothing else. ARGV is where command-line arguments are stored. That's just how UNIX programs work. It's not mentioned in Alfred's documentation because it's a topic for your programming language's docs.
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