Full-featured helper library for writing Alfred 4 and 5 workflows
Project description
A helper library in Python for authors of workflows for Alfred 4 and 5.
Supports Alfred 4 and Alfred 5 on macOS with Python 3.7+.
Alfred-PyWorkflow is a Python 3 port of the original Alfred-Workflow.
Alfred-PyWorkflow takes the grunt work out of writing a workflow by giving you the tools to create a fast and featureful Alfred workflow from an API, application or library in minutes.
Always supports all current Alfred features.
http://www.xdevcloud.de/alfred-pyworkflow/
Features
Auto-saves settings
Super-simple data caching with expiry
Fuzzy, Alfred-like search/filtering with diacritic folding
Keychain support for secure storage of passwords, API keys etc.
Lightweight web API with requests-like interface
Background tasks to keep your workflow responsive
Simple generation of Alfred JSON feedback
Full support of Alfred’s AppleScript/JXA API
Catches and logs workflow errors for easier development and support
“Magic” arguments to help development/debugging
Pre-configured logging
Automatically check for workflow updates via GitHub releases
Post notifications via Notification Center
Advanced modifiers
Set workflow variables from code
Re-running Script Filters
Installation
Note: If you’re new to Alfred workflows, check out the tutorial in the docs.
With pip
You can install Alfred-PyWorkflow directly into your workflow with:
# from your workflow directory pip install --target=. Alfred-PyWorkflow
You can install any other library available on the Cheese Shop the same way. See the pip documentation for more information.
It is highly advisable to bundle all your workflow’s dependencies with your workflow in this way. That way, it will “just work”.
From source
Download the alfred-pyworkflow-X.X.X.zip file from the GitHub releases page.
Extract the ZIP archive and place the workflow directory in the root folder of your workflow (where info.plist is).
Your workflow directory should look something like this (where yourscript.py contains your workflow code and info.plist is the workflow information file generated by Alfred):
Your Workflow/ info.plist icon.png workflow/ __init__.py background.py notify.py update.py version web.py workflow.py yourscript.py etc.
Alternatively, you can clone/download the Alfred-PyWorkflow GitHub repository and copy the workflow subfolder to your workflow’s root directory.
Usage
A few examples of how to use Alfred-PyWorkflow.
Workflow script skeleton
#!/usr/bin/env python3
# encoding: utf-8
import sys
from workflow import Workflow
def main(wf):
# The Workflow instance will be passed to the function
# you call from `Workflow.run`.
# Not super useful, as the `wf` object created in
# the `if __name__ ...` clause below is global...
#
# Your imports go here if you want to catch import errors, which
# is not a bad idea, or if the modules/packages are in a directory
# added via `Workflow(libraries=...)`
import somemodule
import anothermodule
# Get args from Workflow, already as normalized string.
# This is also necessary for "magic" arguments to work.
args = wf.args
# Do stuff here ...
# Add an item to Alfred feedback
wf.add_item('Item title', 'Item subtitle')
# Send output to Alfred. You can only call this once.
# Well, you *can* call it multiple times, but subsequent calls
# are ignored (otherwise the JSON sent to Alfred would be invalid).
wf.send_feedback()
if __name__ == '__main__':
# Create a global `Workflow` object
wf = Workflow()
# Call your entry function via `Workflow.run()` to enable its
# helper functions, like exception catching, ARGV normalization,
# magic arguments etc.
sys.exit(wf.run(main))
Examples
Cache data for 30 seconds:
def get_web_data():
return web.get('http://www.example.com').json()
def main(wf):
# Save data from `get_web_data` for 30 seconds under
# the key ``example``
data = wf.cached_data('example', get_web_data, max_age=30)
for datum in data:
wf.add_item(datum['title'], datum['author'])
wf.send_feedback()
Web
Grab data from a JSON web API:
data = web.get('http://www.example.com/api/1/stuff').json()
Post a form:
r = web.post('http://www.example.com/',
data={'artist': 'Tom Jones', 'song': "It's not unusual"})
Upload a file:
files = {'fieldname' : {'filename': "It's not unusual.mp3",
'content': open("It's not unusual.mp3", 'rb').read()}
}
r = web.post('http://www.example.com/upload/', files=files)
Keychain access
Save password:
wf = Workflow()
wf.save_password('name of account', 'password1lolz')
Retrieve password:
wf = Workflow()
wf.get_password('name of account')
Documentation
The full documentation, including API docs and a tutorial, can be found at xdevcloud.de/alfred-pyworkflow.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for Alfred-PyWorkflow-2.0.0b0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 816069a6c97be8651fe91c2301e41a307a291ce1be7f14c279444ee11cdde8ac |
|
MD5 | f894b8cf7b540dcae8971049781d0c10 |
|
BLAKE2b-256 | 5cb766a5a0ae127cf9ac53b4048df7bf3ef774ae2d5e2f69e4bc8d550eb7f7e5 |