Jump to content

Understanding argument types in keywords and Script Filters


Recommended Posts

For the last few weeks, I've been refining how optional arguments, specifically in Script Filter workflow objects work. This is now what I hope to be the final format. The most interesting one is Optional Argument with Space

 

You can grab b64 with these changes on http://media.alfredapp.com/v2beta/ so make sure your workflow Script Filters work with below :)

 

No Argument

- You script is only run when the typed keyword is matched

- Pressing return or tab will autocomplete keyword

 

Optional Argument [no space]

- Your script is run as soon as the typed keyword is matched

- Pressing return or tab with a partial keyword will autocomplete keyword

 

Optional Argument [with space]

- Your script is run as soon as the typed keyword is matched, regardless of space

- Pressing return or tab with a partial keyword will autocomplete with suffixed space

 

Required Argument [no space]

- Your script is run after the typed keyword is matched AND you start typing an argument

- Pressing return or tab with a partial keyword will autocomplete keyword

 

Required Argument [with space]

- Your script is run after the typed keyword is matched with a trailing space AND you start typing an argument

- Pressing return or tab with a partial keyword will autocomplete with suffixed space

 

Cheers,

Andrew

Link to comment

And can the space be prefixed as soon as you start typing the argument, instead of being suffixed the keyword on autocompletion?

This will also solve the inconsistency between user completed keywords (no suffixed space) vs. autocompletion (suffixed space). 

Link to comment

How does the script filter work, I am trying something like

 

 

if [ $# == 1 ]
then
set query = "url1"
elif [ $# == 2 ]
then
set query = "url2"
fi
 
and linked it to an Open URL action where I have just mentioned the search URL as {query}, but its not working.
Link to comment
  • 2 weeks later...

Andrew, if I attempt to use a space in my argument, Alfred drops out of the script filter completely.  I.e. if I have a script filter for my TV shows folder (keyword 'tv'), and i type:

 

tv the daily

 

when searching for "the daily show", I can't find a way to make that work. I'm just using a rough php preg_match, so I can just do 'tv daily' and that finds it ok, but at this point my curiosity is piqued, so i want to see if its by design that you can't use arguments with spaces, or if there's something afoot here...

Link to comment
... but at this point my curiosity is piqued, so i want to see if its by design that you can't use arguments with spaces, or if there's something afoot here...

You can totally use arguments with spaces. Must be "something afoot" at your end. :P

 

(Quoting issue, perhaps?)

Link to comment
  • 1 month later...

Hey,

 

A question regarding arguments.. I've seen people make workflows that accept arguments containing spaces, but I can't seem to be able to make this work, because the moment I type a space in my argument the workflow switches to "search on google" :(

 

For example, typing "google en text" would search "text" on google.com, while "google de text" would search on google.de (and not to mention the more problematic "google de space separated text" that should search "space separated text" on google.de...

 

Any ideas, advice, how-tos?

 

[later edit] I guess the language mode could be set up using "google en" and "google de" as keywords to trigger the workflow (although it seems like overkill to cover more languages and create a keyword for each one), but the next argument still doesn't work if it has spaces in it

Edited by woofy31
Link to comment

Hey,

 

A question regarding arguments.. I've seen people make workflows that accept arguments containing spaces, but I can't seem to be able to make this work, because the moment I type a space in my argument the workflow switches to "search on google" :(

 

For example, typing "google en text" would search "text" on google.com, while "google de text" would search on google.de (and not to mention the more problematic "google de space separated text" that should search "space separated text" on google.de...

 

Any ideas, advice, how-tos?

 

[later edit] I guess the language mode could be set up using "google en" and "google de" as keywords to trigger the workflow (although it seems like overkill to cover more languages and create a keyword for each one), but the next argument still doesn't work if it has spaces in it

 

Without seeing the code and knowing what your doing, I'm not sure I can be of a whole lot of help right off. Have you wrapped the {query} in quotes to make sure its not dropped because of the space?

Link to comment

On my end it ended up being a copy and paste error.  I was using David's example script and was still passing the {query} through `urlencode`, which was screwing me up.  Removing that fixed the problem.  Now doing quick and dirty regex searches like a boss.

Link to comment

On my end it ended up being a copy and paste error.  I was using David's example script and was still passing the {query} through `urlencode`, which was screwing me up.  Removing that fixed the problem.  Now doing quick and dirty regex searches like a boss.

 

Oh so you're going to blame it on me huh? :) jk, glad you were able to figure it out

Link to comment
  • vitor unpinned this topic

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