Tony_Et Posted April 28, 2017 Share Posted April 28, 2017 (edited) Hi folks! Long time lurker, first time poster, etc., etc. I'm in the midst of writing a new workflow using Deanishe's wonderful alfred-workflow modules, and I'm hitting a wall in regards to using setvar(var, value). I think that I'm expecting it to work differently than it's working, and that my understanding is flawed and I need some help. In the my workflow, keyword "su newticket" and run script "new_ticket.py" is the action I'm concerned with. The upper workflow can be ignored and isn't implemented yet. I'm just trying to call a python script, set a variable, and return it as a {var:<name>} variable. If I use a "copy to clipboard" node, I can see the variable I want embedded in JSON inside {query}, but if I try to access {var:message_out}, there's nothing. This is where I'm falling down Workflow here: https://www.dropbox.com/s/8kjpu6jk4ze4moc/StreetUtils.zip?dl=0 Relevant info: Alfred 3.3.2 [818] macOS 10.12.4 (Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64 x86_64) Alfred-Workflow 1.25.2 Any non-system language you're using (e.g. nodejs): none Any non-system programs you're using (e.g. ffmpeg or youtube-dl) if they aren't bundled in your workflow: none Any changes you've made to your macOS environment (e.g. via launchctl setenv) or the language you're using (e.g. via Python's usercustomize.py or sitecustomize.py files): none I appreciate any advice or guidance! Thanks in advance and all that -tony. Edited April 28, 2017 by Tony_Et deanishe 1 Link to comment
deanishe Posted April 28, 2017 Share Posted April 28, 2017 setvar() only works in Script Filters. If you want to set a variable from a normal Run Script action, you need to do that yourself by printing JSON as described in the sticked variables thread, e.g.: import json message_str = "this is my message" output = { 'alfredworkflow': { 'arg': 'whatever', 'variables': { 'message_out': message_str, } } } print json.dumps(output) Link to comment
Tony_Et Posted April 28, 2017 Author Share Posted April 28, 2017 (edited) Ohhhhhhhhhhhh, right. I knew there was a facepalm coming my way. There it is. In a fit of frustration last night, I almost used json.dumps() (from what I gleaned from your post on it https://www.alfredforum.com/topic/9070-how-to-workflowenvironment-variables/) to shortcut around what I thought setvar() was supposed to be doing, and I completely missed the info that setvar() only works with script filters. Thanks for setting me on the right path! Much appreciated. Edited April 28, 2017 by Tony_Et Link to comment
deanishe Posted April 28, 2017 Share Posted April 28, 2017 I should probably split the variables code into a separate class that can be also used in Run Script actions, tbh. The only reason I haven't done that yet is because I haven't been able to think of a good name for the class. Link to comment
Tony_Et Posted April 28, 2017 Author Share Posted April 28, 2017 I wish I could help you in return. I can only think of something vanilla like "WorkflowVar" or "Variable3", or something completely inappropriate like "BestClassEverReturnVar" Regardless, thanks for the help. Link to comment
vitor Posted April 28, 2017 Share Posted April 28, 2017 2 hours ago, deanishe said: I haven't been able to think of a good name for the class. Ah, yes, one of the two hard problems in computer science: cache invalidation, naming things, and off-by-one errors. Joking aside, my real reason for posting is to thank @Tony_Et for the great bug report. You really followed the guide! Thank you. If all users followed your example our work here would be incredibly easier. deanishe 1 Link to comment
deanishe Posted April 28, 2017 Share Posted April 28, 2017 (edited) I've not heard the variation with the off-by-one error before. Even better. You're spot on about the bug report. Should really be in the Alfred-Workflow thread, but the library seems to "enjoy" assumed official status (possibly because of the name?) But that's by the by. You posted an exemplary issue, @Tony_Et. Took me less than a minute to identify the issue because you gave me everything I needed to do so. It's genuinely a pleasure to help posters like you, who make the effort to make it easy to help. It's also a big help with improving AW's documentation: You clearly tried to figure it out yourself first, but the information you needed was rather between the lines. Now I know what I need to clarify. Edited April 28, 2017 by deanishe I hate this editor vitor 1 Link to comment
Tony_Et Posted May 1, 2017 Author Share Posted May 1, 2017 (edited) @vitor and @deanishe, thanks much again. Also, my apologies, I didn't realize that there was a specific Alfred-Workflow forum; I should have looked (and I'll post there next time). I know it's not an official part of Alfred itself, but for my purposes, it's a critical piece of designing workflows. If it explains anything, My current day job is helping people troubleshoot, so I'm keenly aware of needing to have all the relevant information before solving a problem Edited May 1, 2017 by Tony_Et Link to comment
deanishe Posted May 1, 2017 Share Posted May 1, 2017 FWIW, I've added support for setting variables from Run Script actions to v1.26. Tony_Et 1 Link to comment
Tony_Et Posted May 6, 2017 Author Share Posted May 6, 2017 Used this just today to set some vars from a Run Script. Works great, @deanishe! Thanks for adding that to 1.26 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