Alfred Handlers

Version:
0.2

Introduction

Provides the handlers that take input directly from Alfred.

Discussion

In order to use a handler within Alfred, it is necessary to first load the workflow script. Alfred provides the user's query by string substitution of the {query} text in the script, which is also generally necessary to grab.

To load the workflow script and pass in the user's query, follow this example:

    set workflowFolder to do shell script "pwd"
    set wllib to load script POSIX file (workflowFolder & "/wunderlist.scpt")

    set task to "{query}" as text

    tell wllib
    	addTask(task)
    end tell

It is important to note the text escaping options in Alfred. For this workflow, only the Double Quotes and Backslashes options should be checked. Excess escaping can cause problems handling simple characters such as spaces.



Functions

addList

Adds a new list to Wunderlist

addTask

Adds a task to Wunderlist

addTaskToInbox

Adds a task to the Inbox list in Wunderlist

addTaskToList

Adds a task to the specified list in Wunderlist

run

Provides support for command line operations

showListOptions

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


addList


Adds a new list to Wunderlist

on addList(
    listName)
Parameters
listName

The name of the new list

Discussion

After calling this handler, Wunderlist remains activated with the keyboard focus on the task input for the new list.


addTask


Adds a task to Wunderlist

on addTask(
    task)
Parameters
task

The text of the task, optionally prefixed with a numeric or textual list identifier.

Discussion

To support Script Filter inputs and keyboard entry, the task may be prefixed by a list identifier to insert it into a specific list using addTaskToList. The prefix ensures that the task is added to a specific list. Without it, for example if task is simply 2% milk the task will be added to whichever list is currently visible.

If Wunderlist is on a screen that does not allow task input, such as search results or the Assigned to Me screen, the task will be added in the Inbox.

After calling this handler, the previous application is reactivated. However, if task is not specified, Wunderlist will remain active with the keyboard focus on the task input for the specified list.

List Identifiers

To identify a list by name, task should contain the list name and the text of the task separated by a colon.

    Grocery List:2% milk

To identify a list by index, task should contain the list index and the text of the task separated by two colons. This is primarily for internal use.

    4::2% milk

addTaskToInbox


Adds a task to the Inbox list in Wunderlist

on addTaskToInbox(
    task)
Parameters
task

The text of the task

Discussion

Provides a shortcut for entering tasks directly in the Inbox.

After calling this handler, the previous application is reactivated. However, if task is not specified, Wunderlist will remain active with the keyboard focus on the task input for the Inbox.


addTaskToList


Adds a task to the specified list in Wunderlist

on addTaskToList(
    listIndex,
    task)
Parameters
listIndex

The integer one-based index of the list as it appears in the list table

task

The text of the task

Discussion

Uses focusListAtIndex to focus the specified list, then inserts the task.

If the specified list does not allow task input, such as Assigned to Me or Week, the task will be added in the Inbox.

After calling this handler, the previous application is reactivated. However, if task is not specified, Wunderlist will remain active with the keyboard focus on the task input for the specified list.


run


Provides support for command line operations

on run(
    argv)
Parameters
argv

The list of arguments from the command line

Return Value

1 for success or 0 for error

Commands

showListOptions

See showListOptions, returns 1

updateListInfo

See getListInfo, returns 1 if the lists could be loaded, otherwise 0 (which may occur if Wunderlist is not visible on the current desktop)

forceUpdateListInfo

Ensures that list info is loaded which may require switching to the desktop showing Wunderlist.

showListOptions


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

on showListOptions(
    task)
Parameters
task

The text of the task

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