Jump to content

vidavidorra

Member
  • Content count

    2
  • Joined

  • Last visited

  1. vidavidorra

    Multiple commands/titles (aliases)

    @deanishe Thanks for your reply. I ended up creating a python script which is used as script filter which returns a JSON string as described in the docs. This scripts runs the query on a command list (aliases). It might not be the cleanest solution, but works perfectly so far as I've tested it! import sys import json commands = [ { 'title': 'On', 'arg': 'on', 'command_list': ['on', 'up', 'activate'], 'autocomplete': 'Bluetooth On' }, { 'title': 'Off', 'arg': 'off', 'command_list': ['off', 'down', 'deactivate'], 'autocomplete': 'Bluetooth Off' }, { 'title': 'Restart', 'arg': 'restart', 'command_list': ['toggle', 'change', 'switch'], 'autocomplete': 'Bluetooth Toggle' }, { 'title': 'restart', 'arg': 'restart', 'command_list': ['reset', 'restart'], 'autocomplete': 'Bluetooth Restart' } ] def suggest_command(query): """ Return a JSON object with the commands that start with query. Parameters ---------- query : str Query where the returned commands must start with Returns ------- dict JSON ojbect of commands that start with query None No """ query = query.strip() data = { "items": [] } for command in commands: if any(item.startswith(query) for item in command['command_list']): # print(command['arg']) item = { 'title': command['title'], 'autocomplete': command['autocomplete'], 'arg': command['arg'] } data['items'].append(item) if data['items']: return data else: return None def main(arg): res = suggest_command(arg) if res: print(json.dumps(res)) if __name__ == u'__main__': main(sys.argv[1] if len(sys.argv) > 1 else '')
  2. I'd to use aliases for my commands. E.g. support both `on` and `activate` as commands after the keyword (`bt`) I'm using the script filter json format and tried using the title field as list of strings (works but does show `(` as title in alfred) and use a list of strings as match. Both didn't work, but title came the closest. Alternative would be to add multiple entries with the same arg, but I personally think a list as title or match or something is a cleaner solution. Just don't know whether it's possible. What is the best way to support aliases for commands?
×