コード例 #1
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, 'v:c:q:', ['vendor', 'command', 'query'])
    except getopt.error:
        sys.exit(2)

    vendor = None
    command = None
    query = None

    for opt, arg in opts:
        if opt in ('-v', '--vendor'):
            vendor = arg.strip()
        elif opt in ('-c', '--command'):
            command = arg.strip()
        elif opt in ('-q', '--query'):
            query = arg.strip()

    if vendor and command:
        workflow = alfred.Workflow()
        provider = core.providers.create(vendor, workflow.settings)

        icon = provider.icon

        if command == 'get.profiles':
            profile = provider.profile

            results = map(lambda x: workflow.feedback.Item(
                attributes={'uid': workflow.uid(), 'arg': x['name'], 'valid': u'yes'},
                icon=icon,
                title=x['title'] if x['name'] != profile else u'* %s' % x['title'],
                subtitle=x['full_path']
            ), provider.get_profiles(query))

            if not results:
                results = workflow.feedback.Item(
                    attributes={'uid': workflow.uid(), 'valid': u'no'},
                    icon=icon,
                    title=u'No profiles found',
                    subtitle=u'No profiles were found'
                )

            workflow.feedback.add(results)

            xml = workflow.feedback.to_xml()

            alfred.write(xml)
        elif command == 'set.profile':
            provider.settings.set({'profile': query})
            provider.settings.save()

            alfred.write(u'Now %s uses the "%s" profile' % (provider.name, query))
コード例 #2
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, 'v:c:q:', ['vendor', 'command', 'query'])
    except getopt.error:
        sys.exit(2)

    vendor = None
    command = None
    query = None

    for opt, arg in opts:
        if opt in ('-v', '--vendor'):
            vendor = arg.strip()
        elif opt in ('-c', '--command'):
            command = arg.strip()
        elif opt in ('-q', '--query'):
            query = arg.strip()

    if vendor and command:
        workflow = alfred.Workflow()
        provider = core.providers.create(vendor, workflow.settings)

        icon = provider.icon

        if command == 'get.bookmarks':
            results = map(lambda x: workflow.feedback.Item(
                attributes={'uid': workflow.uid(), 'arg': x['url'], 'valid': u'yes'},
                icon=icon,
                title=x['title'],
                subtitle=x['url']
            ), provider.get_bookmarks(query))

            if not results:
                results = workflow.feedback.Item(
                    attributes={'uid': workflow.uid(), 'valid': u'no'},
                    icon=icon,
                    title=u'No bookmarks found',
                    subtitle=u'No bookmarks matching your query were found'
                )

            workflow.feedback.add(results)

            xml = workflow.feedback.to_xml()

            alfred.write(xml)
コード例 #3
0
ファイル: main.py プロジェクト: ka2er/alfred-workflows
args = alfred.args()

if len(args) > 0:
    query = args[0].strip()
    is_chromium = len(args) > 1;

    if query:
        items = bookmarks.find(query, is_chromium)
        icon = u'icon.png' if not is_chromium else u'icon_chromium.png'

        items = sorted(items, key=lambda x: (x['title'].lower(), x['url'].lower()))
        items = map((lambda x: alfred.Item(
            attributes={'uid': uuid.uuid1().int >> 64, 'arg': x['url'], 'valid': 'yes'},
            icon=icon,
            title=x['title'],
            subtitle=x['url']
        )), items)

        if len(items) == 0:
            items = [alfred.Item(
                attributes={'valid': 'no'},
                icon=icon,
                title=u'No bookmarks found',
                subtitle=u'No bookmarks matching your query were found'
            )]

        xml = alfred.xml(items, len(items))

        alfred.write(xml)