Alfred Script Filters

Version:
0.2

Introduction

Provides filters that take input directly from Alfred for the purpose of filtering lists or selecting options.

Discussion

In order to use a handler within Alfred, simply call the script with two arguments: the name of the filter to call and the user's query.

See the following example for using a bash script to run a filter. Note that backquotes, double quotes, backslashes, and dollar signs should be escaped when providing input this way. Excess escaping can cause problems handling simple characters such as spaces.

    /usr/bin/env php "`pwd`/filters.php" filterListsToAddTask "{query}"

Why PHP? This is a [likely temporary] solution to slow feedback from applescript for list filtering. It was found that a simple Hello World script took 90ms to run with osascript, making AppleScript unsuitable for live filtering. Simple script language alternatives such as Python and PHP were put through similar tests. By far Perl was the fastest. However, in order to be useful the language must have an Alfred workflow library and load it efficiently. Perl did not and Python's two options were both shockingly slow. This left PHP which was capable of 60ms response times once the logic was fully implemented.

Unfortunately, PHP and AppleScript do not play well together when it comes to platform specifics such as localization. This script will likely be replaced with a compiled Cocoa utility that combines speed and platform suitability.



Functions

filterListsToAddTask

A Script Filter input that shows the user's lists in Alfred, allowing a task to be added to a specific list.

getListInfo

Loads list info from the cache or reloads it from Wunderlist

getWorkflowSettings

Loads the workflow's settings.plist into an associative array.


filterListsToAddTask


A Script Filter input that shows the user's lists in Alfred, allowing a task to be added to a specific list.

function filterListsToAddTask(
    $query) 
Parameters
query

The text of the task, optionally specified with a substring of a list name followed by a colon to designate the list into which the task should be added.

Discussion

Queries the Wunderlist UI to provide all of the lists into which new tasks can be added. The response is formatted for Alfred to display in a way that allows the user to type their task, then action a specific list to insert the task there.

After selecting one of these options, the final query will be a concatenation of the list index and the user's task in a format suitable for addTaskToList:

    5::2% milk

The user may also select a list by autocompletion or substring matching. If the query text is a substring of any of the list names, the lists will be filtered to show only those that match. The user can action a list item to autocomplete the list name in the following format:

    Groceries:2% milk

Alternatively, the user can type a colon character indicating that the task is to be entered in the first task matching that substring. The match is case insensitive but is sensitive to accents and other diacritical marks.

    gro:2% milk

getListInfo


Loads list info from the cache or reloads it from Wunderlist

function getListInfo(
    $attempts = 0) 
Parameters
attempts

Guards against infinite recursion, for internal use only

Return Value

an array of associative arrays in the ListInfo format

See


getWorkflowSettings


Loads the workflow's settings.plist into an associative array.

function getWorkflowSettings() 
Return Value

An associative array containing each of the keys from the property list in native PHP data structures.