Jump to content

Modifying user configuration variable from within the workflow

Recommended Posts

If this question is already answered somewhere, please direct me to it – I didn't find anything on it.


What I'd like to do:

  • Given a user config variable, say "TARGET", with a default value provided.
  • Provide a command/keyboard shortcut to change this value persistently from within the workflow


What I tried:

  • Alfred's JXA/JavaScript method 'app.setConfiguration(name, {toValue: "new value", inWorkflow: "bundle.id"});'
  • This works fine with an environment (!) variable in that it changes it to the "new value" (or creates the variable if it doesn't exist). This variable appears in the "Environment tab" of the workflow configuration
  • However, for a variable in the user configuration, the code doesn't change the value. From the script documentation, I'd understand that it should, though: "Modify workflow user configuration value, or set environment variable"


What works _temporarily_ is using the JSON Config action. Is there an approved way to change a user configuration variable programmatically?

Edited by chrillek
Link to comment

The sample workflow is here




Alfred 5.0.5, macOS Ventura 13.0.1


Initially, it uses a User Configuration variable "TestUser" set to "me" and no environment variables.

Triggering the script action with Cmd-1 runs a short JXA script:


function run(argv) {
  const app = Application("Alfred 5");
  app.setConfiguration("TestEnv", {toValue: "you", inWorkflow: "testconfig.bru6.de"});
  app.setConfiguration("TestUser", {toValue: "you", inWorkflow: "testconfig.bru6.de"});


Afterwards, the "Environment Variables" pane contains a new environment variable "TestEnv" with "value" you. The only User Customization variable "TestUser" is still "me". Perhaps I'm doing something stupid here?


Edit: If I remove the User Configuration Variable "TestUser" completely and run the workflow again, "TestUser" is created with the correct value in the Environment Variables.


Edit: The same happens with AppleScript (just tried that since sometimes JXA/JavaScript doesn't work as it should)

Edited by chrillek
Link to comment
  • 4 weeks later...

While this seems to be fixed with 5.0.6, the display in the "User Configuration" tab showing the default value does not change. So, it's possible to set a user config value to "B" while the tab still shows "A". I think that's a bit unfortunate. Shouldn't the dialog reflect the current setting? If so, the label should be changed from "default" to "current", too.

Link to comment

No. The window is closed. And I restarted Alfred, out of superstition. Setting the value of "TestUser" to "them" and then running the workflow shows that "TestUser" is "you" even _before_ the script is run.


Now, the _correct_ value (i.e. "you") is stored in prefs.plist, while info.plist contains




It seems that info.plist stores the default user config value and doesn't change it, while it _does_ change the environment variable's value (as is reflected in info.plist _and_ the dialog). OTOH, prefs.plist stores the _current_ value of the user config value, which the dialog does _not_ show.

Bildschirm­foto 2022-12-16 um 12.36.27.png

Bildschirm­foto 2022-12-16 um 12.38.59.png

Link to comment

Yes, that is exactly how it’s supposed to work. You posted a screenshot of the back end configuration; that’s for you as the workflow’s creator to set up, not for users to change. It should and does only list the default value, which is what it returns to when the field is empty.

Click Configure Workflow… on the top left, that’s where the user facing part is, which is what’s shown when you install or update a workflow.

Link to comment

In my understanding, Configure Workflow should be set up by the developer to provide reasonable default values. That's why the label is "Default Value". My idea was

- to provide some kind of default value for a workflow

- to provide a method for the user to change that value to something else


If and when the user changes this value with the provided method, how are they going to see the current value? When they open the configuration dialog, all they'll see is the default value set by the developer, not the current value set by themselves.  Or is this the wrong approach and should I rather use an environment variable for this user modifiable setting?

Link to comment

So that’s why you’re trying to change the values programatically? You don’t need to do that.


5 minutes ago, chrillek said:

to provide some kind of default value for a workflow


That’s what you do in the User Configuration tab under the [x] on the right.


5 minutes ago, chrillek said:

to provide a method for the user to change that value to something else


That’s what the Configure Workflow… on the left is for.


7 minutes ago, chrillek said:

If and when the user changes this value with the provided method, how are they going to see the current value?


In the same place where they changed if, in Configure Workflow…. They can even change it again or reset to defaults.

See the documentation:

Configuring your Workflow as a creator
Configuring an Installed Workflow

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...