chopstick
All widgets

Convert Units

Comes with Chopstick

Type an amount in search, like 25kg or 100 F in C, to see it converted. Return copies the answer; click it to edit.

Already installed? It's in your widget library.

Type it in the notch's search

  • Convert amount

What it runs

A widget is a folder of plain files. Here is all of its code.

widget.json
{
  "id": "convert",
  "name": "Convert Units",
  "icon": "icon.png",
  "description": "Type an amount in search, like 25kg or 100 F in C, to see it converted. Return copies the answer; click it to edit.",
  "anytime": false,
  "initial": "help",
  "commands": {
    "convert": {
      "description": "Convert an amount to another unit and copy the answer (25kg, 5 mi in km, 100 F to C).",
      "phrase": "Convert {amount}",
      "inputs": {
        "amount": { "type": "quantity", "description": "An amount with a unit, optionally followed by \"in\" or \"to\" and the unit to convert to" }
      },
      "preview": { "state": "converted" },
      "do": [ { "copy": "{{input.amount.to.text}}" }, { "go": "copied" } ]
    },
    "show": {
      "description": "Show an amount converted to another unit (25kg, 5 mi in km, 100 F to C).",
      "inputs": {
        "amount": { "type": "quantity", "description": "An amount with a unit, optionally followed by \"in\" or \"to\" and the unit to convert to" }
      },
      "do": [ { "set": { "error": "" } }, { "go": "converted" } ]
    }
  },
  "states": {
    "help": {
      "task": true,
      "open": true,
      "compact": { "leading": { "symbol": "arrow.left.arrow.right" } },
      "expanded": {
        "size": "regular",
        "header": { "symbol": "arrow.left.arrow.right", "title": "Convert Units" },
        "blocks": [
          { "input": { "placeholder": "25kg in lb", "do": [ { "command": "show", "with": { "amount": "{{item.text}}" } } ] } },
          { "note": "{{error | Or type an amount in search (⌥Space): 25kg, 5 mi in km, 100 F to C.}}" }
        ]
      }
    },
    "converted": {
      "task": true,
      "open": true,
      "compact": { "leading": { "symbol": "arrow.left.arrow.right" }, "trailing": { "text": "{{input.amount.to.text}}" } },
      "expanded": {
        "size": "regular",
        "header": { "symbol": "arrow.left.arrow.right", "title": "Convert Units" },
        "blocks": [
          { "row": [
              { "stack": [ { "text": "{{input.amount.text}}", "style": "title" }, { "text": "{{input.amount.name}}", "style": "caption" } ] },
              { "text": "→", "style": "title" },
              { "stack": [ { "text": "{{input.amount.to.text}}", "style": "title" }, { "text": "{{input.amount.to.name}}", "style": "caption" } ] }
            ], "align": "center", "spacing": "loose" },
          { "input": { "placeholder": "25kg in lb", "value": "{{input.amount.text}} in {{input.amount.to.unit}}",
                       "do": [ { "command": "show", "with": { "amount": "{{item.text}}" } } ] } },
          { "note": "{{error}}" }
        ]
      },
      "keys": [ { "key": "cmd+c", "label": "Copy", "do": [ { "copy": "{{input.amount.to.text}}" }, { "go": "copied" } ] } ]
    },
    "copied": {
      "task": true,
      "dismiss_after": 2,
      "compact": { "leading": { "symbol": "doc.on.doc", "tint": "green" }, "trailing": { "text": "{{input.amount.to.text}}" } }
    }
  }
}