alfred 2.0.1

A library for writing Alfred workflows. http://www.alfredapp.com

Crate alfred [] [src]

Helpers for writing Alfred script filter output

Examples

XML output (Alfred 2)

extern crate alfred;

use std::io::{self, Write};

fn write_items() -> io::Result<()> {
    let mut xmlw = try!(alfred::XMLWriter::new(io::stdout()));

    let item1 = alfred::Item::new("Item 1");
    let item2 = alfred::ItemBuilder::new("Item 2")
                                    .subtitle("Subtitle")
                                    .into_item();
    let item3 = alfred::ItemBuilder::new("Item 3")
                                    .arg("Argument")
                                    .subtitle("Subtitle")
                                    .icon_filetype("public.folder")
                                    .into_item();

    try!(xmlw.write_item(&item1));
    try!(xmlw.write_item(&item2));
    try!(xmlw.write_item(&item3));

    let mut stdout = try!(xmlw.close());
    stdout.flush()
}

fn main() {
    match write_items() {
        Ok(()) => {},
        Err(err) => {
            let _ = writeln!(&mut io::stderr(), "Error writing items: {}", err);
        }
    }
}

JSON output (Alfred 3)

extern crate alfred;

use std::io::{self, Write};

fn write_items() -> io::Result<()> {
    alfred::json::write_items(io::stdout(), &[
        alfred::Item::new("Item 1"),
        alfred::ItemBuilder::new("Item 2")
                            .subtitle("Subtitle")
                            .into_item(),
        alfred::ItemBuilder::new("Item 3")
                            .arg("Argument")
                            .subtitle("Subtitle")
                            .icon_filetype("public.folder")
                            .into_item()
    ])
}

fn main() {
    match write_items() {
        Ok(()) => {},
        Err(err) => {
            let _ = writeln!(&mut io::stderr(), "Error writing items: {}", err);
        }
    }
}

Reexports

pub use self::xml::XMLWriter;

Modules

env

Accessors for workflow environment variables

json

Helpers for writing Alfred script filter JSON output (Alfred 3)

xml

Helpers for writing Alfred script filter XML output (Alfred 2)

Structs

Item

Representation of an <item>

ItemBuilder

Helper for building Item values

ModifierData

Optional overrides of subtitle, arg, and valid for modifiers.

Enums

Icon

Item icons

ItemType

Item types

Modifier

Keyboard modifiers