I’m not sure, but I don’t think I can do this with the Alfred app …
What I’d like to do is define a custom function, e.g. “change”.
“change(x, y)” would return the result of doing (y-x)/x. I do this calculation all the time.
For example change(50, 100) would return 1.
Is there an app which would allow me to type a keyboard shortcut, a window would open up like Alfred’s, I could type in “change(50, 100)”, and it would return “1”?
The most convenient solution for you will depend on which automation tools are on your Mac. One tool I know you have is AppleScript. Here’s a script that will do it:
set change to display dialog "Give me two numbers separated by a single space" with title "Change" default answer "50 100" buttons {"Change", "Cancel"} default button "Change" cancel button "Cancel"
set my text item delimiters to " "
set x to text item 1 of (text returned of change)
set y to text item 2 of (text returned of change)
set c to (y - x) / x
display alert "The change from " & x & " to " & y & " is " & c
Unfortunately, I don’t know enough about running scripts from Alfred to get this bound to a keyboard shortcut (I’m more of a Keyboard Maestro guy). I’m sure someone else here can help you with that and probably clean up my script, too.
Relevant parts. You can just accept change 50,100 instead of adding support on line 3 for change(50,100) (choose no space after input) by taking a substring inside the parentheses. I like to support the parentheses because it feels right.