Jump to content

Is there a way to keep all spaces in a query when using a script filter? [Fixed 3.4 b837 pre-release]


GuiB

Recommended Posts

I'm not sure if this is a bug, but I'm trying to get a query with multiple spaces in it and "as is" (meaning that I want the the left and right trailing spaces). Right now, Alfred trim the spaces to only one if multiple are inserted at the beginning or end of a query. This is working if using a "keyword input" so it seems to be a problem with the script filter input method. I've tried using the "with input as argv" or "with input as {query}" and both output the same.

 

Here is my test script for the Script Filter input (using Python):

import sys, json

query = sys.argv[1]
#query = """{query}"""  # uncomment if trying with "with input as {query}"

data = {
    'items': [{
        'title': "Script Filter: The query is '" + query + "'",
        'arg': query
    }]
}
sys.stdout.write(json.dumps(data))

Here is a screencast to show the problem: https://NoFile.io/f/4334MTCdPQ5/Alfred-SpaceInQuery-Problem.mov

 

Is this a bug or there's something I'm not doing well or it's just not possible with the Script Filter input ?

Thanks!

 

 

 

Edited by GuiB
Link to comment
Share on other sites

Anyone has any idea ? Or maybe I didn't post to the right section and a moderator could move my question to the "Workflow Help & Questions" section or the "Bug Reports" section if you think it better fit, thanks a lot!

Link to comment
Share on other sites

Not sure if this is a bug or a feature.

 

At any rate, the behaviour is inconsistent. Preceding spaces are maintained so long as there is at most one trailing space. With 2 or more trailing spaces, the trailing spaces are reduced to one and all preceding whitespace is trimmed.

 

I'd say "bug", so that's where I'll move it…

Link to comment
Share on other sites

Thanks deanishe!

 

Yes, this is what I thought that it must be a bug because of it's inconsistency and because it doesn't act as the "keyword input", but thought that it could be a feature as well to make the input cleaner to the user script. However, if it's a feature I think it should be possible to bypass it by the workflow developper in case it is not wanted. Maybe a checkbox in the Scipt Filter input window to specify if we want the query to be trimmed or not would be great.

 

Thanks for your help!

Link to comment
Share on other sites

@GuiB @deanishe Interesting, and something I haven't looked at for quite some time.

 

Firstly, it's correct that Alfred is trying to make things more efficient and prevent scripts from running unnecessarily. I've actually identified a little bug where it's trimming the query instead of trimming the trailing spaces, which is why you're seeing that odd leading behaviour. I've just fixed that.

 

As this is the first time this has come up, could I ask the use case for needing the spaces as being significant? It's possible I may remove the trimming altogether rather than adding an option to make spaces significant.

 

Cheers,

Andrew

Link to comment
Share on other sites

Hi @Andrew, thanks for investigating the issue!

 

As for my use case, I wanted to develop a workflow to find and replace text in the macOS selection using a series of 2 queries: the first one to determine what to find in the text and the second one to what to replace with. I wanted to have the Find & Replace script to be useful for multiple case, so for example to replace a word with another one or something more relating to coding, for example to convert tabs to the number of spaces wanted.

 

Ex:

     - Replace query1("hello") with query2("hi")

     - Replace query1("\t") with query2("  ")     -> Here replace tabs with 2 spaces

     - Replace query1("    ") with query2("\t")   -> Here replace 4 spaces with a tab

     - Replace query1("\n") with query2(" ")     -> Here replace newline with 1 spaces

    ...

 

So, I would like the query to really not be trimmed (left or right trailing spaces) if that's possible

 

Thanks again!

 

Edited by GuiB
Link to comment
Share on other sites

  • Andrew changed the title to Is there a way to keep all spaces in a query when using a script filter? [Fixed 3.4 b837 pre-release]

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