Jump to content

How to share environment variables with workflow scripts


Recommended Posts

Hello!

 

First post to this forum!

 

I just created my first workflow, which I'd like to share with my team. Problem is, my workflow includes a script which references a private API key, which I would rather not share with the team.

 

Is there any way I can share the workflow, without exposing the script's API key? For instance, by replacing the API key in the script with a reference to an environment variable instead?

 

Appreciate the assistance.

 

Many thanks!

Steve 

Link to comment

There's little point using environmental variables, as Alfred doesn't use your (shell) environment. Apps use launchd's environment, which is pretty much empty.
 
Your best bet is to store user-specific settings in the place Alfred expects you to: ~/Library/Application Support/Alfred 2/Workflow Data/YOUR.BUNDLE.ID

 

 Anything you put in the workflow directory gets deleted when the user updates the workflow.

 

If you're using Python, this library will help. It can even store the API key in Keychain for you.
 
To do it "ghetto" style, set up your workflow to run bash scripts and then call Python scripts from the Script box like in a shell (this is a good practice anyway). You can then set the envvar in the wrapper:

[[ -f "$HOME/.workflow_api_key" ]] && { export API_KEY=$(cat "$HOME/.workflow_api_key") }
 
/usr/bin/python myscript.py --option "{query}"
Edited by deanishe
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...