Workflow Builder for Alfred 2

1.0.5 2013-07-04 23:56 UTC

This package is auto-updated.

Last update: 2024-04-06 14:50:26 UTC


Alfred Workflow Builder is a PHP class for creating workflows with Alfred 2. This class provides functions for working with plist settings files, reading and writing data to files, generating Alfred feedback results, and more.


Composer is the recommended way to install is package. Composer is dependency management tool for PHP that allows you to declare the dependencies your project needs and installs them into your project.

  1. Add skyzyx/alfred-workflow-builder as a dependency in your project's composer.json file.

        "require": {
            "skyzyx/alfred-workflow-builder": "1.0.*"
  2. Download and install Composer.

    curl -s "" | php
  3. Install your dependencies.

    php composer.phar install --optimize-autoloader
  4. Require Composer's autoloader. Composer also prepares an autoload file that's capable of autoloading all of the classes in any of the libraries that it downloads. To use it, just add the following line to your code's bootstrap process.

    require 'vendor/autoload.php';

The original version of this class (written by David Ferguson) had methods for things like caching data to local files and fetching remote data over HTTP. Instead, we recommend you use Guzzle, Requests or Buzz for HTTP requests and Doctrine Cache for local file system caching. If you'd also like logging, we recommend Monolog.


use Alfred\Workflow;

// Pass a Bundle ID
$w = new Workflow('');
#=> <Alfred\Workflow>

string toXML()

Accepts a properly formatted array or json object and converts it to XML for creating Alfred feedback results. If results have been created using the result() function, then passing no arguments will use the array of results created using the result() function.

Example using result function

    'uid'          => 'itemuid',
    'arg'          => 'itemarg',
    'title'        => 'Some Item Title',
    'subtitle'     => 'Some item subtitle',
    'icon'         => 'icon.png',
    'valid'        => 'yes',
    'autocomplete' => 'autocomplete'
echo $w->toXML();

Example using array

$results = array();
$temp = array(
    'uid'          => 'itemuid',
    'arg'          => 'itemarg',
    'title'        => 'Some Item Title',
    'subtitle'     => 'Some item subtitle',
    'icon'         => 'icon.png',
    'valid'        => 'yes',
    'autocomplete' => 'autocomplete'
array_push($results, $temp);
echo $w->toXML($results);


<?xml version="1.0"?>
    <item uid="itemuid" arg="itemarg" autocomplete="autocomplete">
        <title>Some Item Title</title>
        <subtitle>Some item subtitle</subtitle>

array mdfind()

Executes an mdfind command and returns results as an array of matching files.

$results = $w->mdfind('"kMDItemContentType =="');
/* or */
$results = $w->mdfind('Alfred');
#=> (array) ['/Applications/Alfred']

You can learn more about querying the OS X metadata service by checking out:

array result()

Creates a new result item that is cached within the class object. This set of results is available via the results() functions, or, can be formatted and returned as XML via the toXML() function.

Key Usage

Unique ID for the search result. (Required)


Argument for this result. This will get fed into any downstream actions. (Required)


The main title for the result. (Required)


The subtitle for the result. (Required)


The icon that this result should have. This should typically be icon.png. (Required)


If you press enter with this result selected, should it trigger downstream actions? Valid values are "yes", "no", true and false. The default value is "yes".


If you press enter with this result selected, what value should pop up as an autocomplete value? (Movies is a good usage example.)


$w->result(array (
    'uid'          => 'alfred',
    'arg'          => 'alfredapp',
    'title'        => 'Alfred',
    'subtitle'     => '/Applications/',
    'icon'         => 'fileicon:/Applications/',
    'valid'        => 'yes',
    'autocomplete' => 'Alfredapp',
echo $w->toXML();


<?xml version="1.0"?>
    <item uid="alfred" arg="alfredapp" autocomplete="Alfredapp">
        <icon type="fileicon">/Applications/</icon>


use Alfred\Storage\Plist;

// Pass a Bundle ID and Plist name
$plist = new Plist('', 'info');
#=> <Alfred\Storage\Plist>

string setValue()

Stores a key-value pair.

$plist->setValue('username', 'rparman');

string setValues()

Stores a series of key-value pairs.

    'username' => 'rparman',
    'password' => 'abc123',
    'zipcode'  => '90210',

string getValue()

Retrieves the value of a key.

$username = $plist->getValue('username');
#=> (string) rparman


You can learn more about Alfred 2 Workflows by checking out

You can also deconstruct some workflows that are built with Alfred Workflow Builder.