pub struct Item { /* private fields */ }
Expand description
An Alfred script filter item.
Implementations§
source§impl Item
impl Item
sourcepub fn uid(self, uid: impl Into<String>) -> Self
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.
sourcepub fn arg(self, arg: impl Into<String>) -> Self
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.
sourcepub fn args<I, J>(
self,
args: impl IntoIterator<Item = impl Into<String>>
) -> Self
pub fn args<I, J>( self, args: impl IntoIterator<Item = impl Into<String>> ) -> Self
Set the arguments which are passed through the workflow to the connected output action.
Same as arg
, but allows you to pass multiple arguments.
sourcepub fn icon(self, icon: Icon) -> Self
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.
sourcepub fn valid(self, valid: bool) -> Self
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.
sourcepub fn matches(self, matches: impl Into<String>) -> Self
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.
sourcepub fn autocomplete(self, autocomplete: impl Into<String>) -> Self
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).
sourcepub fn copy_text(self, copy: impl Into<String>) -> Self
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.
sourcepub fn large_type_text(self, large_type: impl Into<String>) -> Self
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.
sourcepub fn quicklook_url(self, quicklook_url: impl Into<String>) -> Self
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.
sourcepub fn modifier(self, modifier: Modifier) -> Self
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.
sourcepub fn action(self, action: impl Into<Value>) -> Self
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"
}));