Supercharge your Alfred 🎩 workflows by building them in Rust 🦀!
This project contains a powerpack crate which provides types for developing
script filter Alfred workflows in Rust as well as various utilities that make it
easier to build workflows. It also provides a command line tool to initialize,
build, and install workflows built using the powerpack crate.
Firstly, install the command line tool. Now create a new
project using a similar API as cargo new or cargo init.
powerpack new myworkflow && cd myworkflowThis will create a new Rust project as well as a workflow/ directory
containing information about your Alfred workflow. The following will create
a release build of the workflow and copy it to the workflow/ directory.
powerpack build --releaseNow you can link it to Alfred. The following will symlink the workflow/
directory to the Alfred preferences folder.
powerpack linkNow you can run the workflow from Alfred ✨!
To package a .alfredworkflow file for release you can run the following.
powerpack packageThe release will be available at target/workflow/myworkflow.alfredworkflow.
powerpack can be installed from my personal tap which includes pre-built
binaries.
brew install rossmacarthur/tap/powerpackpowerpack can be installed from
Crates.io using
Cargo, the Rust package manager.
cargo install powerpack-cliIn some circumstances this can fail due to the fact that Cargo does not use
Cargo.lock file by default. You can force Cargo to use it using the --locked
option.
cargo install powerpack-cli --lockedPre-built binaries for macOS (aarch64, x86_64) are provided. These can be downloaded directly from the the releases page.
Alternatively, the following script can be used to automatically detect your
host system, download the required artifact, and extract the powerpack binary
to the given directory.
curl --proto '=https' -fLsS https://rossmacarthur.github.io/install/crate.sh \
| bash -s -- --repo rossmacarthur/powerpack --to ~/.local/binThe following is a "Hello World!" Alfred workflow built using powerpack.
use std::env;
use std::error::Error;
use std::iter;
fn main() -> Result<(), Box<dyn Error>> {
// Alfred passes in a single argument for the user query.
let arg = env::args().nth(1);
let query = arg.as_deref().unwrap_or("");
// Create an item to show in the Alfred drop down.
let item = powerpack::Item::new("Hello World!")
.subtitle(format!("Your query was '{}'", query));
// Output the item to Alfred!
powerpack::output(iter::once(item))?;
Ok(())
}This would render an item as shown.
setup-crate can be used to install powerpack in a GitHub Actions
workflow. For example:
steps:
- uses: actions/checkout@v2
- uses: extractions/setup-crate@v1
with:
repo: rossmacarthur/powerpack
- run: powerpack package
# produces an artifact at `target/workflow/{name}.alfredworkflow`The following projects are built using powerpack.
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
