Jump to content

What's the difference between {query} and argv input modes?


Recommended Posts

When creating a python workflow I use to set /bin/bash with {query} as input.


In this case I call my script by using python myscript.py “{query}” so that I can get the argument with sys.argv[1].


My question is: what’s the point of argv as input mode? Is there a meaningful difference when I am working with Python?


I know that Alfred recommends argv above {query} because with the first one you are not supposed to need worring about scaping the inputted query but I really don’t get it.


If I call my script with python myscript.py “$1” I get the same result with sys.argv[1] that I would get using python myscript.py “{query}”.


I know that I might be missing something obvious. So please, be patient.

Edited by xilopaint
Link to post

ARGV is a better model. Apart from being the standard UNIX way to run programs, it's simpler (no language-specific escaping) and faster (no need for Alfred to re-write your script every time it runs it).

 

{query} is still around for backwards compatibility, I guess.

 

Link to post

The fact you’re always only using a single argument and always calling an external script makes them the same in your cases. ARGV isn’t simply $1, but also $#, and $@, and $2 (and every other integer), so it can be decomposed in ways {query} cannot (without you specifically doing the splitting). Straight from the changelog:

 

Quote

When using argv, file lists (e.g. from an Action trigger) are passed as separate arguments

 

In your example, /bin/bash with {query} as input isn’t arguably the most appropriate option. You have an External Script option in Language. That should just call the script directly instead of having to call bash to call your script.

 


 

Unrelated question: are you using MarkdownBulletin? I ask because your code text looks like the one it used a long time ago, but it has since changed to what @deanishe and I have right now. Just mentioning it in case you have an outdated Workflow and want to update (it since gained auto-update capabilities).

Edited by vitor
Link to post

@vitor, I agree External Script option looks the best choice for my case. But I have dozens of workflows of the Alfred community, including 13 created by you, and I couldn't find a single one that makes use of this option. Is there any reason for this? It should fit in many cases, shouldn't it?

Edited by xilopaint
Link to post
3 minutes ago, xilopaint said:

Is there any reason for this?

 

That option is much more recent than the others, so in my case I haven’t used it simply because it wasn’t there when I first wrote most of my Workflows and I never bothered to change it, or forgot to when I had the chance.


It’s also rare for me to have Worfklows that just call a script, like in your example. I typically have some more logic inside the Script box.

Link to post
On 31/03/2017 at 8:38 PM, deanishe said:

I write File Filters, too, you know.

 

That comment confused me and I had to reread the initial posts a few times until the misunderstanding hit me. My first post — and every single word of mine on this thread prior to this reply — was directed at @xilopaint, not you.

 

The block of test you quoted is referring to @xilopaint’s examples in the top post. His examples — which seemed to be indicative of how he usually writes Workflows — all used only a single argument and always called an external script. That’s what I was referring to. I had already written most of my post (including that section) when you replied.

 

I have more Workflows from you than any other single user apart from myself. You’re the most knowledgeable Workflow developer I know, you’ve built one of the most popular Alfred libraries, and I interact with your skills frequently on these forums. Far from me to think I’d teach you anything about ARGV!

Edited by vitor
Link to post
31 minutes ago, vitor said:

every single word of mine on this thread prior to this reply — was directed at @xilopaint

 

Aaah, right. Sorry.

 

32 minutes ago, vitor said:

Far from me to think I’d teach you anything about ARGV

 

I wouldn't bet on it. I got a PR today to fix a bug because apparently I can't remember how my own library works :( 

 

 

At any rate, it's a very important point that ARGV works much better with File Actions than {query} does.

Link to post

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