Skip to main content

Full-featured helper library for writing Alfred 2/3/4 workflows, with Python 3

Project description

alfred-workflow-tddschn logo

Note: this is a fork of the amazing https://github.com/deanishe/alfred-workflow and has some differences.

alfred-workflow-tddschn

A helper library in Python for authors of workflows for Alfred 3 and 4.

Build Status Coverage Status Development Status Latest Version Supported Python Versions

Supports Alfred 3 and Alfred 4 on macOS 10.7+ (Python 3.7+).

alfred-workflow-tddschn 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.

Features

  • Auto-saved settings API for your workflow
  • Super-simple data caching with expiry
  • Fuzzy filtering (with smart diacritic folding)
  • Keychain support for secure storage of passwords, API keys etc.
  • 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
  • Unicode support
  • Pre-configured logging
  • Automatically check for workflow updates via GitHub releases
  • Post notifications via Notification Center

Alfred 4+ features

  • Advanced modifiers
  • Alfred 4-only updates (won't break older Alfred installs)

Contents

Installation

Note: If you're new to Alfred workflows, check out the tutorial in the docs.

With pip

You can install alfred-workflow-tddschn directly into your workflow with:

# from your workflow directory
pip install --target=. alfred-workflow-tddschn

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

  1. Download the alfred-workflow-X.X.X.zip from the GitHub releases page.
  2. Extract the ZIP archive and place the workflow directory in the root folder of your workflow (where info.plist is).

Your workflow should look something like this:

Your Workflow/
    info.plist
    icon.png
    workflow/
        __init__.py
        background.py
        notify.py
        Notify.tgz
        update.py
        version
        workflow.py
    yourscript.py
    etc.

Alternatively, you can clone/download the alfred-workflow-tddschn repository and copy the workflow subdirectory to your workflow's root directory.

Usage

A few examples of how to use alfred-workflow-tddschn.

Workflow script skeleton

Set up your workflow scripts as follows (if you wish to use the built-in error handling or sys.path modification):

#!/usr/bin/python
# encoding: utf-8

import sys

# Workflow3 supports Alfred 3's new features. The `Workflow` class
# is also compatible with Alfred 2.
from workflow import Workflow3


def main(wf):
    # The Workflow3 instance will be passed to the function
    # you call from `Workflow3.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 `Workflow3(libraries=...)`
    import somemodule
    import anothermodule

    # Get args from Workflow3, already in normalized Unicode.
    # This is also necessary for "magic" arguments to work.
    args = wf.args

    # Do stuff here ...

    # Add an item to Alfred feedback
    wf.add_item(u'Item title', u'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 `Workflow3` object
    wf = Workflow3()
    # Call your entry function via `Workflow3.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():
    import json
    from urllib import request
    with request.urlopen('http://www.example.com') as f:
      data = f.read().decode('utf-8')
    return json.loads(data)

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()

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 deanishe.net.

Dash docset

The documentation is also available as a Dash docset.

Licensing, thanks

The code and the documentation are released under the MIT and Creative Commons Attribution-NonCommercial Licenses respectively. See License.txt for details.

The documentation was generated using Sphinx and a modified version of the Alabaster theme by bitprophet.

Many of the cooler ideas in alfred-workflow-tddschn were inspired by Alfred2-Ruby-Template by Zhaocai.

The Keychain parser was based on Python-Keyring by Jason R. Coombs.

Contributing

Adding a workflow to the list

If you want to add a workflow to the list of workflows using alfred-workflow-tddschn, don't add it to the docs! The list is machine-generated from Packal.org and the library_workflows.tsv file. If your workflow is available on Packal, it will be added on the next update. If not, please add it to library_workflows.tsv, and submit a corresponding pull request.

The list is not auto-updated, so if you've released a workflow and are keen to see it in this list, please open an issue asking me to update the list.

Bug reports, pull requests

Please see the documentation.

Contributors

Workflows using alfred-workflow-tddschn

Here is a list of some of the many workflows based on alfred-workflow-tddschn.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

alfred-workflow-tddschn-0.1.5.tar.gz (91.0 kB view details)

Uploaded Source

Built Distribution

alfred_workflow_tddschn-0.1.5-py3-none-any.whl (87.3 kB view details)

Uploaded Python 3

File details

Details for the file alfred-workflow-tddschn-0.1.5.tar.gz.

File metadata

  • Download URL: alfred-workflow-tddschn-0.1.5.tar.gz
  • Upload date:
  • Size: 91.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.5 Darwin/22.1.0

File hashes

Hashes for alfred-workflow-tddschn-0.1.5.tar.gz
Algorithm Hash digest
SHA256 2776bdbc10670938df0e23d5473f50c5f29b771c9ea2a3474061f1d9bf619cdc
MD5 826a61bce8ca29176ffd5379c119c6ae
BLAKE2b-256 8a3462d640165f1af88dbb191fd139e19de342b0fd2b4c736c49dd015beb4c46

See more details on using hashes here.

File details

Details for the file alfred_workflow_tddschn-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for alfred_workflow_tddschn-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8b91320671b98b49079c5015e825de8cf483d58b09e83d3fb63a709125503798
MD5 d5703f500c7503a9810815e6f4d12f2c
BLAKE2b-256 74ee7482fe329afbd2529f1991872da5a8d1eeedfdc8a1c9b282c45060ee60cb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page