GuiB Posted May 28, 2017 Posted May 28, 2017 (edited) 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 May 28, 2017 by GuiB
GuiB Posted May 31, 2017 Author Posted May 31, 2017 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!
deanishe Posted May 31, 2017 Posted May 31, 2017 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…
GuiB Posted May 31, 2017 Author Posted May 31, 2017 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!
Andrew Posted May 31, 2017 Posted May 31, 2017 @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
GuiB Posted May 31, 2017 Author Posted May 31, 2017 (edited) 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 May 31, 2017 by GuiB
Andrew Posted May 31, 2017 Posted May 31, 2017 @GuiB I've added a ticket to look into this. An option may be added as an option under the "Run Behaviour" allowing all typed characters to be preserved (defaulting to the fixed current behaviour). Cheers, Andrew
Andrew Posted June 2, 2017 Posted June 2, 2017 @GuiB This option is now available under the "Run Behaviour" button within the Script Filter workflow object config sheet if you update to the b837 pre-release
GuiB Posted June 2, 2017 Author Posted June 2, 2017 Hi @Andrew, thanks for the update ! At first try this is working great! So thanks a lot ! Also, I saw the new snippet workflow trigger, this would be a very great addition! Thanks for your work Andrew 1
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