Skip to content

Alfred Script Filters

Resources

Format

{"items": [
    {
        "uid": "desktop",
        "type": "file",
        "title": "Desktop",
        "subtitle": "~/Desktop",
        "arg": "~/Desktop",
        "autocomplete": "Desktop",
        "icon": {
            "type": "fileicon",
            "path": "~/Desktop"
        }
    }
]}

By default, Alfred uses title for searching over items. But if the items contain symbols like "/", "-", "_", it makes it harder for items to show up.

Use match to clean up such strings 👇.

$ python -c "import random, string;print(*[(''.join(random.choice(string.ascii_lowercase+ '-' + '-') for i in range(10))) for j in range(4)], sep='\n')" | jq -R -n -c '[inputs|split(",")|{uid:.[0], title: .[0], match: (.[0]|split("-")|join(" ")), subtitle: .[0], arg: .[0]}] | {items: .}|.' | jq

Main transformation to note: match: (.[0] | split("-") | join(" "))

{
  "items": [
    {
      "uid": "wf-pktieqa",
      "title": "wf-pktieqa",
      "match": "wf pktieqa",
      "subtitle": "wf-pktieqa",
      "arg": "wf-pktieqa"
    },
    {
      "uid": "vea-xkximk",
      "title": "vea-xkximk",
      "match": "vea xkximk",
      "subtitle": "vea-xkximk",
      "arg": "vea-xkximk"
    },
    {
      "uid": "svwavhjbfh",
      "title": "svwavhjbfh",
      "match": "svwavhjbfh",
      "subtitle": "svwavhjbfh",
      "arg": "svwavhjbfh"
    },
    {
      "uid": "xpcm-pt-fm",
      "title": "xpcm-pt-fm",
      "match": "xpcm pt fm",
      "subtitle": "xpcm-pt-fm",
      "arg": "xpcm-pt-fm"
    }
  ]
}

Ordering

By default, Alfred orders the results based on past behaviour if a UID is included. Don't set a UID if the script filter should show results in the order they are in the JSON array.