alfy icon indicating copy to clipboard operation
alfy copied to clipboard

Support setting Alfred variables with alfy.output

Open luca-aurelia opened this issue 8 years ago • 9 comments

Issuehunt badges

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)

Submitted pull Requests


Become a backer now!

Or submit a pull request to get the deposits!

Tips

luca-aurelia avatar Jan 11 '17 03:01 luca-aurelia

I didn't know about this, but would definitely be useful. A pull request would be lovely :D

sindresorhus avatar Jan 11 '17 07:01 sindresorhus

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 avatar Feb 20 '17 00:02 mdeboer

@mdeboer https://github.com/sindresorhus/alfy/issues/54

sindresorhus avatar Jun 23 '17 01:06 sindresorhus

How is this coming along? Would be really useful. :)

tormodvm avatar Apr 28 '18 22:04 tormodvm

Agreed, would be really useful!

davidmerrick avatar Feb 22 '19 22:02 davidmerrick

For anyone that wants to work on this, see the discussion and feedback in https://github.com/sindresorhus/alfy/pull/44.

sindresorhus avatar Jun 10 '19 17:06 sindresorhus

@issuehunt has funded $60.00 to this issue.


IssueHuntBot avatar Jun 11 '19 01:06 IssueHuntBot

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

sindresorhus avatar Jun 03 '21 19:06 sindresorhus

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:

image

SCR-20220816-gha

image

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

hoto avatar Aug 16 '22 10:08 hoto