Hey, thanks for the awesome tool.

I constantly need to make some simple calculations and that's one of a feature that I liked about Alfred.

With ScriptKit I think I made it slightly better:

  • live preview of your calculation
  • select to copy to clipboard
  • remembers last 10 calculations
  • auto fixing , to . - so you don't have to do it manually

https://user-images.githubusercontent.com/1018759/116007328-8f126600-a60f-11eb-8588-4a978bac47c9.mov

// Menu: Simple calculator
// Description: Make simple calculations
// Author: Jakub Olek
// Twitter: @JakubOlek
// Shortcut: opt =
const calcDb = db('calc', {history: []});
function createResult(calculationResult, input) {
return {name: calculationResult, description: input, value: {calculationResult, input}}
}
const {calculationResult, input, ...rest} = await arg("calculate:", async (input) => {
const choices = [];
if (input) {
choices.push(createResult((await exec(`bc <<<"${input.replace(/\,/g, ".")}" -l`)).replace(/^\./, "0."), input))
}
return choices.concat(calcDb.get('history').value())
})
if (calculationResult) {
const history = calcDb.get('history').value();
history.unshift(createResult(calculationResult, input));
calcDb.set('history', history.filter(({description}, index) => index === 0 || description !== input).slice(0, 10)).write()
}
copy(calculationResult)