Code Monkey home page Code Monkey logo

powerpack's Introduction

⚡ powerpack

Crates.io Version Docs.rs Latest Build Status

Supercharge your Alfred 🎩 workflows by building them in Rust 🦀!

🚀 Getting started

This project contains a powerpack crate which provides types for developing script filter Alfred workflows in Rust. It also provides a command line tool to initialize, build, and install workflows built using the powerpack crate.

Firstly, install the command line tool.

cargo install powerpack-cli

Now create a new project using a similar API as cargo new or cargo init.

powerpack new myworkflow && cd myworkflow

This 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 --release

Now you can link it to Alfred. The following will symlink the workflow/ directory to the Alfred preferences folder.

powerpack link

Now you can run the workflow from Alfred ✨!

To package a .alfredworkflow file for release you can run the following.

powerpack package

The release will be available at target/workflow/myworkflow.alfredworkflow.

🤸 Usage

The 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.

image

👷 GitHub Action

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:
      owner: rossmacarthur
      name: powerpack
  - run: powerpack package
  # produces an artifact at `target/workflow/{name}.alfredworkflow`

💡 Examples

The following projects are built using powerpack.

License

Licensed under either of

at your option.

powerpack's People

Contributors

danbi2990 avatar knutwalker avatar rossmacarthur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

powerpack's Issues

powerpack-cli fails to install

Running cargo install powerpack-cli fails with the following errors:

   Compiling powerpack-cli v0.2.1
error[E0432]: unresolved import `clap::Clap`
  --> /Users/jvimberg/.cargo/registry/src/github.com-1ecc6299db9ec823/powerpack-cli-0.2.1/src/main.rs:12:25
   |
12 | use clap::{AppSettings, Clap};
   |                         ^^^^ no `Clap` in the root

error: cannot determine resolution for the derive macro `Clap`
   --> /Users/jvimberg/.cargo/registry/src/github.com-1ecc6299db9ec823/powerpack-cli-0.2.1/src/main.rs:169:17
    |
169 | #[derive(Debug, Clap)]
    |                 ^^^^
    |
    = note: import resolution is stuck, try simplifying macro imports

error: cannot find attribute `clap` in this scope
   --> /Users/jvimberg/.cargo/registry/src/github.com-1ecc6299db9ec823/powerpack-cli-0.2.1/src/main.rs:174:11
    |
174 |         #[clap(long)]
    |           ^^^^
    |
    = note: `clap` is in scope, but it is a crate, not an attribute

error: cannot find attribute `clap` in this scope
   --> /Users/jvimberg/.cargo/registry/src/github.com-1ecc6299db9ec823/powerpack-cli-0.2.1/src/main.rs:180:11
    |
180 |         #[clap(long)]
    |           ^^^^
    |
    = note: `clap` is in scope, but it is a crate, not an attribute

error: cannot find attribute `clap` in this scope
   --> /Users/jvimberg/.cargo/registry/src/github.com-1ecc6299db9ec823/powerpack-cli-0.2.1/src/main.rs:185:11
    |
185 |         #[clap(long)]
    |           ^^^^
    |
    = note: `clap` is in scope, but it is a crate, not an attribute

error: cannot determine resolution for the derive macro `Clap`
   --> /Users/jvimberg/.cargo/registry/src/github.com-1ecc6299db9ec823/powerpack-cli-0.2.1/src/main.rs:194:17
    |
194 | #[derive(Debug, Clap)]
    |                 ^^^^
    |
    = note: import resolution is stuck, try simplifying macro imports

error: cannot find attribute `clap` in this scope
   --> /Users/jvimberg/.cargo/registry/src/github.com-1ecc6299db9ec823/powerpack-cli-0.2.1/src/main.rs:195:3
    |
195 | #[clap(
    |   ^^^^
    |
    = note: `clap` is in scope, but it is a crate, not an attribute

error: cannot find attribute `clap` in this scope
   --> /Users/jvimberg/.cargo/registry/src/github.com-1ecc6299db9ec823/powerpack-cli-0.2.1/src/main.rs:206:7
    |
206 |     #[clap(subcommand)]
    |       ^^^^
    |
    = note: `clap` is in scope, but it is a crate, not an attribute

error[E0599]: no function or associated item named `parse` found for struct `Opt` in the current scope
   --> /Users/jvimberg/.cargo/registry/src/github.com-1ecc6299db9ec823/powerpack-cli-0.2.1/src/main.rs:211:32
    |
205 | struct Opt {
    | ---------- function or associated item `parse` not found for this
...
211 |     let Opt { command } = Opt::parse();
    |                                ^^^^^ function or associated item not found in `Opt`
    |
    = help: items from traits can only be used if the trait is implemented and in scope
    = note: the following traits define an item `parse`, perhaps you need to implement one of them:
            candidate #1: `combine::parser::Parser`
            candidate #2: `combine::parser::ParseMode`
            candidate #3: `Parser`
            candidate #4: `time::parsing::parsable::sealed::Sealed`

Some errors have detailed explanations: E0432, E0599.
For more information about an error, try `rustc --explain E0432`.
error: failed to compile `powerpack-cli v0.2.1`, intermediate artifacts can be found at `/var/folders/6c/wbbn4x0s393716pfk79xwttc0000gn/T/cargo-installK4t9kX`

Caused by:
  could not compile `powerpack-cli` due to 9 previous errors

Icon variant names are confusing

pub enum Icon<'a> {
    /// Load an image from a path.
    Path(PathBuf),
    /// Extract the icon from a file.
    File(PathBuf),
    /// Uniform Type Identifier (UTI) icon.
    FileType(String<'a>),
}
  • Icon::Path is a path to an icon file.
  • Icon::File means that Alfred will use the icon for that file. I.e. if the file is a JPEG then it will use the following icon:
  • Icon::FileType is a way to specify the UTI e.g. public.jpeg will be the above icon.

We should change the variant names so that this is clearer.

Support variables

From the Alfred workflow documentation

Variables / Session Variables

Variables within a variables object will be passed out of the script filter and remain accessible throughout the current session as environment variables.

In addition, they are passed back in when the script reruns within the same session. This can be used for managing state between runs as the user types input or when the script is set to re-run after an interval.

{
    "variables": {
        "fruit": "banana",
        "vegetable": "carrot"
    },
    "items": [
        ...
    ]
}

See the built in "Advanced Script Filter" getting started guide for more info, and to see this in practice.

Item Variables

Individual item objects can have variables which are passed out of the Script Filter object if the associated result item is selected > in Alfred's results list. variables set within an item will override any JSON session variables of the same name.

It is also possible to add a variables object for each mod in the item object, allowing you to differentiate when a mod result is selected within your workflow. Note that when setting a variables object on a mod, this replaces the item variables, and doesn't inherit from them, allowing maximum flexibility.

When a mod doesn't contain a variables object, it will assume the item variables. To prevent this, add an empty variables object: "variables": {}.

How to create a workflow that opens an application with a parameter?

Hello, thanks for this lib. I already use it for searching and opening bookmarks and it works great.

I would like to create a workflow, that opens a directory with intellij or vscode.
e.g. idea /path/to/repository or IntelliJ IDEA Ultimate.app /path/to/repository

The Modifier-class seems to change arguments, but I don't see how I can specifly which application/command to execute. When I look at other workflows, it looks like I have to change the info.plist.

Could you help me out? Do you have an example?

thanks in advance and best regards
Joscha

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.