GuiB Posted July 3, 2021 Posted July 3, 2021 The "Call External" workflow objet allow to pass the environment variables to the called workflow. It would be great to be able to do the same when calling it from AppleScript. It would be great to simply add an option (ex: "withEnvVar" that when set to true the environment variables will be sent to the called workflow trigger. If it's a problem, then the "withEnvVar" could use a string that would represent the JSON value for the "variables" section of an Alfred JSON configuration like: { "alfredworkflow" : { "arg" : "{query}", "config" : { }, "variables" : withEnvVar_will_represent_this } } In other words, a "withEnvVar" could use a JSON string like: "{ \"focusedapp\": \"com.apple.finder\" }" We can send a full JSON string to the "with argument", but we then need to interpret it on the called workflow which make it problematics if we want to be able to call it using both method: one workflow calling the other from AppleScript and another workflow calling the other but by using the "Call External" workflow object.
deanishe Posted July 3, 2021 Posted July 3, 2021 (edited) 28 minutes ago, GuiB said: We can send a full JSON string to the "with argument", but we then need to interpret it on the called workflow which make it problematics if we want to be able to call it using both method: one workflow calling the other from AppleScript and another workflow calling the other but by using the "Call External" workflow object. If you just echo the arg in a Run Script, you should end up in the same place regardless of whether you used External Trigger or AppleScript: Alfred will interpret the JSON for you and set any workflow variables defined in it. The solution of passing a JSON string via AppleScript is not a good (official) one, imo. For one thing, AppleScript doesn't support JSON, making producing valid JSON problematic, and for another AppleScript already has native types that could be used to pass a mapping of variables. Edited July 3, 2021 by deanishe
GuiB Posted July 3, 2021 Author Posted July 3, 2021 1 minute ago, deanishe said: If you just echo the arg in a Run Script, you should end up in the same place regardless of whether you used External Trigger or AppleScript: Alfred will interpret the JSON for you and set any workflow variables defined in it. You mean, to send the complete JSON string as argument to the "run trigger" then yes you're right, but I think it would be easier with a simple boolean value that would ask Alfred to send the environment variable then building the JSON string from AppleScript and as you said, it's not the best language for this so that's why I thought of passing a smaller part of the JSON string, but yes I would prefer not having to do it and simply asking with a boolean value. I'll try to change my script to JavaScript for automation to make it easier to build the JSON string for the argument! Thanks!
deanishe Posted July 3, 2021 Posted July 3, 2021 10 minutes ago, GuiB said: You mean, to send the complete JSON string as argument to the "run trigger" then yes you're right Yeah. You could at least avoid parsing the JSON yourself that way. 11 minutes ago, GuiB said: building the JSON string from AppleScript JSON is a no-go for the AppleScript API, imo. It'd be nuts to require a format the language doesn't support, especially when you could just pass a native AS map (a record) to the API. It would be differently nuts in JXA. Why require a JSON-encoded JS object for a JS-native API when you could just pass the object itself? 18 minutes ago, GuiB said: I'll try to change my script to JavaScript for automation to make it easier to build the JSON string for the argument! A very good idea. Trying to assemble valid JSON without a proper library is very difficult to get right.
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