Welcome to Alfred-Workflow¶
Go to Quick Index.
Alfred-Workflow is a Python helper library for Alfred 2, 3 and 4 workflow authors, developed and hosted on GitHub.
Alfred workflows typically take user input, fetch data from the Web or elsewhere, filter them and display results to the user. Alfred-Workflow takes care of a lot of the details for you, allowing you to concentrate your efforts on your workflow’s functionality.
Alfred-Workflow supports macOS 10.7+ (Python 2.7).
Features¶
- Fuzzy, Alfred-like search/filtering with diacritic folding
- Simple, persistent settings
- Simple, auto-expiring data caching
- Keychain support for secure storage (and syncing) of passwords, API keys etc.
- Simple generation of Alfred feedback (XML and JSON)
- Lightweight web API with requests-like interface
- Easily launch background tasks (daemons) to keep your workflow responsive
- Check for and install new workflow versions using GitHub releases
- Post notifications with Notification Center (10.8+ only)
- Error handling and logging for easier development and support
- “Magic” arguments to help development, debugging and management of the workflow
Alfred 3+ features¶
- Set workflows variables from code
- Advanced modifiers
- Alfred version-aware updates (ignores incompatible updates)
- Automatic re-running of Script Filters.
Quick example¶
Here’s how to show recent Pinboard.in posts in Alfred.
Create a new workflow in Alfred’s preferences. Add a Script Filter with
Language /usr/bin/python
and paste the following into the Script
box (changing API_KEY
):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import sys
from workflow import Workflow, ICON_WEB, web
# To use Alfred 3+ feedback mechanism:
# from workflow import Workflow3
API_KEY = 'your-pinboard-api-key'
def main(wf):
url = 'https://api.pinboard.in/v1/posts/recent'
params = dict(auth_token=API_KEY, count=20, format='json')
r = web.get(url, params)
r.raise_for_status()
for post in r.json()['posts']:
wf.add_item(post['description'], post['href'], arg=post['href'],
uid=post['hash'], valid=True, icon=ICON_WEB)
wf.send_feedback()
if __name__ == u"__main__":
wf = Workflow()
sys.exit(wf.run(main))
|
Add an Open URL action to your workflow with {query}
as the URL,
connect your Script Filter to it, and you can now hit ENTER on a
Pinboard item in Alfred to open it in your browser.
Warning
Using the above example code as a workflow will likely get you banned by the Pinboard API. See the Tutorial if you want to build an API terms-compliant (and super-fast) Pinboard workflow.
Using Alfred-Workflow¶
- Supported versions
- Installation
- Tutorial
- User Guide
- Workflow setup and skeleton
- Including 3rd party libraries
- Persistent data
- Searching/filtering data
- Retrieving data from the web
- Notifications
- Background processes
- Self-updating
- Versioning and migration
- System icons
- “Magic” arguments
- Workflow variables
- Serialization of stored/cached data
- Re-running a Script Filter
- Encoded strings and Unicode
- API documentation