Jump to content

How to share environment variables with workflow scripts

Recommended Posts



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!


Share this post

Link to post

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

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...