Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting Alfred variables with alfy.output #43

Open
luca-aurelia opened this issue Jan 11, 2017 · 9 comments
Open

Support setting Alfred variables with alfy.output #43

luca-aurelia opened this issue Jan 11, 2017 · 9 comments
Labels
💵 Funded on Issuehunt This issue has been funded on Issuehunt enhancement help wanted

Comments

@luca-aurelia
Copy link

luca-aurelia commented Jan 11, 2017

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

@sindresorhus
Copy link
Owner

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

@mdeboer
Copy link

mdeboer commented Feb 20, 2017

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": [
    ...
  ]
}

@sindresorhus
Copy link
Owner

@mdeboer #54

@tormodvm
Copy link

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

@davidmerrick
Copy link

Agreed, would be really useful!

@sindresorhus
Copy link
Owner

For anyone that wants to work on this, see the discussion and feedback in #44.

@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label Jun 11, 2019
@IssueHuntBot
Copy link

@issuehunt has funded $60.00 to this issue.


@sindresorhus
Copy link
Owner

If anyone wants to work on this, see the initial attempt in and the feedback given there: #122 (comment)

@hoto
Copy link

hoto commented Aug 16, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💵 Funded on Issuehunt This issue has been funded on Issuehunt enhancement help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants