Skip to content

Commit

Permalink
Add rerunInterval option (#121)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
jopemachine and sindresorhus authored Aug 16, 2020
1 parent 134c8dc commit de0213a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ alfy.alfred = {

alfy.input = process.argv[2];

alfy.output = items => {
console.log(JSON.stringify({items}, null, '\t'));
alfy.output = (items, {rerunInterval} = {}) => {
console.log(JSON.stringify({items, rerun: rerunInterval}, null, '\t'));
};

alfy.matches = (input, list, item) => {
Expand Down
30 changes: 29 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ Type: `string`

Input from Alfred. What the user wrote in the input box.

#### output(list)
#### output(list, options?)

Return output to Alfred.

Expand All @@ -204,6 +204,34 @@ alfy.output([
]);
```

##### options

Type: `object`

###### rerunInterval

Type: `number` *(seconds)*\
Values: `0.1...0.5`

A script can be set to re-run automatically after some interval. The script will only be re-run if the script filter is still active and the user hasn't changed the state of the filter by typing and triggering a re-run. [More info.](https://www.alfredapp.com/help/workflows/inputs/script-filter/json/)

For example, it could be used to update the progress of a particular task:

```js
alfy.output(
[
{
title: 'Downloading Unicorns…',
subtitle: `${progress}%`,
}
],
{
// Re-run and update progress every 3 seconds.
rerunInterval: 3
}
);
```

<img src="media/screenshot-output.png" width="694">

#### log(value)
Expand Down

0 comments on commit de0213a

Please sign in to comment.