Code Monkey home page Code Monkey logo

alfred-python's Introduction

alfred-python

Pythonic and lightweight access to the Alfred workflow API. If you need inspiration of how to use it, look at the following lines:

import alfred

>>> import alfred
>>> print alfred.bundleid
nikipore.alfredpython
>>> print alfred.preferences['description']
Python library for Alfred workflow API
>>> alfred.bundleid
'nikipore.alfredpython'
>>> alfred.preferences['description'] # access to info.plist
'Python library for Alfred workflow API'
>>> alfred.work(volatile=True) # access to (and creation of) the recommended storage paths
'/Users/jan/Library/Caches/com.runningwithcrayons.Alfred-2/Workflow Data/nikipore.alfredpython'
>>> alfred.work(volatile=False)
'/Users/jan/Library/Application Support/Alfred 2/Workflow Data/nikipore.alfredpython'
>>> alfred.config()
'config'
>>> item = alfred.Item({'uid': 1, 'arg': 'some arg'}, 'some title', 'some subtitle')
>>> str(item)
'<item arg="some arg" uid="1"><title>some title</title><subtitle>some subtitle</subtitle></item>'
>>> item = alfred.Item({'uid': alfred.uid(1), 'arg': 'some arg', 'valid': 'no'}, 'some title', 'some subtitle', ('someicon.png', {'type': 'filetype'}))
>>> str(item)
'<item arg="some arg" uid="nikipore.alfredpython-1" valid="no"><title>some title</title><subtitle>some subtitle</subtitle><icon type="filetype">someicon.png</icon></item>'

The boilerplate for your Alfred workflow is reduced to something like this:

# -*- coding: utf-8 -*-
(parameter, query) = alfred.args() # proper decoding and unescaping of command line arguments
results = [item(
    attributes= {'uid': alfred.uid(0), 'arg': u'https://www.google.de/q=%s' % query},
    title=parameter,
    subtitle=u'simple access to the Alfred workflow API'
)] # a single Alfred result
xml = alfred.xml(results) # compiles the XML answer
alfred.write(xml) # writes the XML back to Alfred

You are also invited to look at the workflows implemented with alfred-python:

Please feel free to contribute more workflows implemented with alfred-python here, or add functionality to/fix bugs on alfred-python.

alfred-python's People

Contributors

deanishe avatar isometry avatar krzysztofr avatar nikipore avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.