chrillek Posted November 13, 2022 Share Posted November 13, 2022 (edited) 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 November 13, 2022 by chrillek Link to comment
vitor Posted November 13, 2022 Share Posted November 13, 2022 The AppleScript method is the way to do it. If it’s not working for you, please provide a simple reproducible test case, along with your version of macOS and Alfred. Link to comment
chrillek Posted November 13, 2022 Author Share Posted November 13, 2022 (edited) The sample workflow is here https://bru6.de/jxa/downloads/test.alfredworkflow 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 November 17, 2022 by chrillek Bump Link to comment
chrillek Posted November 18, 2022 Author Share Posted November 18, 2022 Any news on this? Link to comment
vitor Posted November 19, 2022 Share Posted November 19, 2022 (edited) We were able to identify the cause, keep an eye out for the next release for the fix. In the meantime, if you edit the configuration once by hand, it’ll then work with AppleScript/JXA. Edited November 19, 2022 by vitor chrillek 1 Link to comment
chrillek Posted December 16, 2022 Author Share Posted December 16, 2022 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
vitor Posted December 16, 2022 Share Posted December 16, 2022 2 minutes ago, chrillek said: the display in the "User Configuration" tab showing the default value does not change. I cannot reproduce that. Do you have the configuration window open while you’re changing the value in the background? Link to comment
chrillek Posted December 16, 2022 Author Share Posted December 16, 2022 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 <key>userconfigurationconfig</key> <array> <dict> <key>config</key> <dict> <key>default</key> <string>them</string> <key>placeholder</key> <string></string> <key>required</key> <false/> <key>trim</key> <true/> </dict> <key>description</key> <string></string> <key>label</key> <string>TestUser</string> <key>type</key> <string>textfield</string> <key>variable</key> <string>TestUser</string> </dict> </array> 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. Link to comment
vitor Posted December 16, 2022 Share Posted December 16, 2022 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
chrillek Posted December 16, 2022 Author Share Posted December 16, 2022 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
vitor Posted December 16, 2022 Share Posted December 16, 2022 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
chrillek Posted December 16, 2022 Author Share Posted December 16, 2022 I see. So I was trying to solve a non-existing problem. Thanks for clarifying! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now