That works. But you could do the same more simply by putting the command keywords in match and letting Alfred do the filtering:
import json
import sys
commands = [
{
'title': 'On',
'arg': 'on',
'match': 'on up activate',
'autocomplete': 'Bluetooth On',
},
{
'title': 'Off',
'arg': 'off',
'match': 'off down deactivate',
'autocomplete': 'Bluetooth Off',
},
{
'title': 'Restart',
'arg': 'restart',
'match': 'toggle change switch',
'autocomplete': 'Bluetooth Toggle',
},
{