alfy
alfy copied to clipboard
Support setting Alfred variables with alfy.output
You can set variables in Alfred by writing to stdout using a special JSON format. It would be handy if alfy.output
supported this, perhaps in a special variables
key:
alfy.output([
{ title: 'Google', arg: 'https://www.google.com', variables: { browser: 'Chrome' },
{ title: 'Mozilla', arg: 'https://www.mozilla.org', variables: { browser: 'Firefox' } }
])
Or as a second argument:
// backwards compatible, but less elegant
alfy.output([
{ title: 'Google', arg: 'https://www.google.com' },
{ title: 'Mozilla', arg: 'https://www.mozilla.org' }
], [
{ browser: 'Chrome' },
{ browser: 'Firefox' }
])
I'm happy to write a pull request if this seems worthwhile.
JSON Format
The format for emitting variables isn't complicated, but life would be easier if Alfy handled it.
Emit a string and set variables
// The root `alfredworkflow` key is required.
// Without it, Alfred will pass the object to the next node in the workflow like normal.
{
"alfredworkflow": {
"arg": "https://www.google.com",
"variables": {"browser": "Chrome"}
}
}
Emit multiple items and set variables
// `arg` is a stringified `alfredworkflow` object
{
"items": [{
"title": "Google",
"arg": "{\"alfredworkflow\": {\"arg\": \"https://www.google.com\", \"variables\": {\"browser\": \"Chrome\"}}}"
}]
}
Note, you can access Alfred variables through the environment:
const browser = process.env.browser
IssueHunt Summary
Backers (Total: $60.00)
-
issuehunt ($60.00)
Submitted pull Requests
Become a backer now!
Or submit a pull request to get the deposits!
Tips
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on IssueHunt to raise funds.
I didn't know about this, but would definitely be useful. A pull request would be lovely :D
Cool! Could you maybe add support for the "rerun" parameter as well? See: https://www.alfredapp.com/help/workflows/inputs/script-filter/
{
"rerun" : 1,
"items": [
...
]
}
@mdeboer https://github.com/sindresorhus/alfy/issues/54
How is this coming along? Would be really useful. :)
Agreed, would be really useful!
For anyone that wants to work on this, see the discussion and feedback in https://github.com/sindresorhus/alfy/pull/44.
@issuehunt has funded $60.00 to this issue.
- Submit pull request via IssueHunt to receive this reward.
- Want to contribute? Chip in to this issue via IssueHunt.
- Checkout the IssueHunt Issue Explorer to see more funded issues.
- Need help from developers? Add your repository on IssueHunt to raise funds.
If anyone wants to work on this, see the initial attempt in and the feedback given there: https://github.com/sindresorhus/alfy/pull/122#issuecomment-854110355
ATM the workaround to pass multiple variables to the workflow that I found is to pass an array as arg
and split it into multiple variables like so:
{
title: `${key}`,
subtitle: `${summary}`,
arg: [jiraUrl, key, summary, kebabCaseSummary], // hack to pass variables to the workflow
...
Then you split the output into variables like so:


Example: https://github.com/hoto/alfred-my-jira-tickets/blob/master/mapper.js#L14