Struct powerpack::Item

source ·
pub struct Item { /* private fields */ }
Expand description

An Alfred script filter item.

Implementations§

source§

impl Item

source

pub fn new(title: impl Into<String>) -> Self

Create a new item with the provided title.

source

pub fn subtitle(self, subtitle: impl Into<String>) -> Self

Set the subtitle for this item.

source

pub fn uid(self, uid: impl Into<String>) -> Self

Set the UID for this item.

This is a unique identifier for the item which allows help Alfred to learn about this item for subsequent sorting and ordering of the user’s actioned results.

It is important that you use the same UID throughout subsequent executions of your script to take advantage of Alfred’s knowledge and sorting. If you would like Alfred to always show the results in the order you return them from your script, exclude the UID field.

source

pub fn arg(self, arg: impl Into<String>) -> Self

Set the argument which is passed through the workflow to the connected output action.

While this attribute is optional, it’s highly recommended that you populate this as it’s the string which is passed to your connected output actions. If excluded, you won’t know which result item the user has selected.

source

pub fn args<I, J>( self, args: impl IntoIterator<Item = impl Into<String>> ) -> Self
where I: IntoIterator<Item = J>, J: Into<String>,

Set the arguments which are passed through the workflow to the connected output action.

Same as arg, but allows you to pass multiple arguments.

source

pub fn icon(self, icon: Icon) -> Self

Set the icon displayed in the result row.

Workflows are run from their workflow folder, so you can reference icons stored in your workflow relatively.

source

pub fn valid(self, valid: bool) -> Self

Set whether this item is valid or not.

If an item is valid then Alfred will action this item when the user presses return. If the item is not valid, Alfred will do nothing. This allows you to intelligently prevent Alfred from actioning a result based on the current query passed into your script.

If you exclude the valid attribute, Alfred assumes that your item is valid.

source

pub fn matches(self, matches: impl Into<String>) -> Self

Set the text that Alfred will match against.

This field enables you to define what Alfred matches against when the workflow is set to “Alfred Filters Results”. If match is present, it fully replaces matching on the title property.

Note that the match field is always treated as case insensitive, and intelligently treated as diacritic insensitive. If the search query contains a diacritic, the match becomes diacritic sensitive.

source

pub fn autocomplete(self, autocomplete: impl Into<String>) -> Self

Set the autocomplete value for this item.

An optional but recommended string you can provide which is populated into Alfred’s search field if the user auto-complete’s the selected result (⇥ by default).

source

pub fn kind(self, kind: Kind) -> Self

Set the type of item.

source

pub fn copy_text(self, copy: impl Into<String>) -> Self

Set the text the user will get when copying the selected result row with ⌘C or displaying large type with ⌘L.

If these are not defined, you will inherit Alfred’s standard behaviour where the arg is copied to the Clipboard or used for Large Type.

source

pub fn large_type_text(self, large_type: impl Into<String>) -> Self

Set the text the user will get when displaying large type with ⌘L.

If this is not defined, you will inherit Alfred’s standard behaviour where the arg is used for Large Type.

source

pub fn quicklook_url(self, quicklook_url: impl Into<String>) -> Self

Set the Quick Look URL for the item.

This will be visible if the user uses the Quick Look feature within Alfred (tapping shift, or ⌘Y). This field will also accept a file path, both absolute and relative to home using ~/.

If absent, Alfred will attempt to use the arg as the quicklook URL.

source

pub fn modifier(self, modifier: Modifier) -> Self

Add a modifier key configuration.

This gives you control over how the modifier keys react. For example you can define the valid attribute to mark if the result is valid based on the modifier selection and set a different arg to be passed out if actioned with the modifier.

source

pub fn action(self, action: impl Into<Value>) -> Self

Set the Universal Action item(s).

This element defines the Universal Action items used when actioning the result, and overrides the arg being used for actioning. The action key can take a string or array for simple types, and the content type will automatically be derived by Alfred to file, url, or text.

Examples

Single item:

let item = Item::new("Title").action("Alfred is Great");

Multiple Items:

let item = Item::new("Title").action(value!(["Alfred is Great", "I use him all day long"]));

For control over the content type of the action, you can use an object with typed keys:

let item = Item::new("Title").action(value!({
    "text": ["one", "two", "three"],
    "url": "https://www.alfredapp.com",
    "file": "~/Desktop",
    "auto": "~/Pictures"
}));

Trait Implementations§

source§

impl Clone for Item

source§

fn clone(&self) -> Item

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Item

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Item

source§

fn default() -> Item

Returns the “default value” for a type. Read more
source§

impl PartialEq for Item

source§

fn eq(&self, other: &Item) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Item

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Eq for Item

source§

impl StructuralEq for Item

source§

impl StructuralPartialEq for Item

Auto Trait Implementations§

§

impl RefUnwindSafe for Item

§

impl Send for Item

§

impl Sync for Item

§

impl Unpin for Item

§

impl UnwindSafe for Item

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.