Jump to content

NPS Calculator Workflow

Recommended Posts



I am attempting to create a NPS calculator in Alfred where I only have to enter the numbers with command and it provides the score for me. (For context, this website has the formula on the bottom.) I believe based on the error log I am getting, it is something with the Script I have set up using bin/zsh. 


Is anyone able to provide some assistance? Thanks in advance!




PS: Here are the test numbers I am using starting with 0 (red) and going to 10 (green): 1,0,0,0,0,2,1,4,2,4,26

Link to comment

Welcome @Ahess97,


In bash you access variables with ${var}, not {var}. Also, you’re calling bc but doing nothing with it, as if you were calling it interactively in a Terminal. This being a script, you need to give your data as the input to bc. Use <<< to feed data, or < to feed a file. Meaning what you want is:

bc -l <<< "(((${nps11}+${nps10})-(${nps7}+${nps6}+${nps5}+${nps4}+${nps3}+${nps2}+${nps1}))/(${nps11}+${nps10}+${nps9}+${nps8}+${nps7}+${nps6}+${nps5}+${nps4}+${nps3}+${nps2}+${nps1}))*100"

Link to comment

Thank you! That is super helpful to know how terminal and scripts differ.


One final question: my output has many 0s following the NPS score. (65.00000000000000000000). I think using the transform function using regex would solve this problem, but I don't know much about regex

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