All widgets
Calculator
Comes with Chopstick
Type a sum in search, like 2^10 / (3+5), 15% of 80 or sqrt(2) * pi, to see the answer. Return copies it; click it to edit.
Already installed? It's in your widget library.





Type it in the notch's search
- Calculate sum
What it runs
A widget is a folder of plain files. Here is all of its code.
widget.json
{
"id": "calculator",
"name": "Calculator",
"description": "Type a sum in search, like 2^10 / (3+5), 15% of 80 or sqrt(2) * pi, to see the answer. Return copies it; click it to edit.",
"icon": "icon.png",
"anytime": false,
"initial": "help",
"commands": {
"calculate": {
"description": "Work out a sum and copy the answer (2^10 / (3+5), 80 + 15%, sqrt(2) * pi).",
"phrase": "Calculate {sum}",
"inputs": {
"sum": { "type": "expression", "description": "Arithmetic: + - * / ^, parentheses, %, sqrt sin cos tan log ln abs round floor ceil, pi, e" }
},
"preview": { "state": "answered" },
"do": [ { "copy": "{{input.sum.text}}" }, { "go": "copied" } ]
},
"show": {
"description": "Show the answer to a sum (2^10 / (3+5), 80 + 15%, sqrt(2) * pi).",
"inputs": {
"sum": { "type": "expression", "description": "Arithmetic: + - * / ^, parentheses, %, sqrt sin cos tan log ln abs round floor ceil, pi, e" }
},
"do": [ { "set": { "error": "" } }, { "go": "answered" } ]
}
},
"states": {
"help": {
"task": true,
"open": true,
"compact": { "leading": { "symbol": "equal.square" } },
"expanded": {
"size": "regular",
"header": { "symbol": "equal.square", "title": "Calculator" },
"blocks": [
{ "input": { "placeholder": "2^10 / (3+5)", "do": [ { "command": "show", "with": { "sum": "{{item.text}}" } } ] } },
{ "note": "{{error | Or type a sum in search (⌥Space): 15% of 80, 80 + 15%, sqrt(2) * pi.}}" }
]
}
},
"answered": {
"task": true,
"open": true,
"compact": { "leading": { "symbol": "equal.square" }, "trailing": { "text": "{{input.sum.text}}" } },
"expanded": {
"size": "regular",
"header": { "symbol": "equal.square", "title": "Calculator" },
"blocks": [
{ "text": "{{input.sum.expression}} =", "style": "caption", "truncate": "head" },
{ "text": "{{input.sum.text}}", "style": "title" },
{ "input": { "placeholder": "2^10 / (3+5)", "value": "{{input.sum.expression}}",
"do": [ { "command": "show", "with": { "sum": "{{item.text}}" } } ] } },
{ "note": "{{error}}" }
]
},
"keys": [ { "key": "cmd+c", "label": "Copy", "do": [ { "copy": "{{input.sum.text}}" }, { "go": "copied" } ] } ]
},
"copied": {
"task": true,
"dismiss_after": 2,
"compact": { "leading": { "symbol": "doc.on.doc", "tint": "green" }, "trailing": { "text": "{{input.sum.text}}" } }
}
},
"preview": {
"states": [ "help", "answered", "copied" ],
"data": { "input": { "sum": { "value": 128, "text": "128", "expression": "2^10 / (3+5)" } } }
}
}