Jump to content

I don't know which part of the workflow I need to modify


Recommended Posts

Currently, the results are supposed to be printed by pressing the space bar, but I want the results to be printed right away without pressing the space bar.

 

How do I modify it?

 

Thank you in advance 🙏

Workflow Download

 

import sys
sys.path.append("lib")
import re
from workflow import Workflow3
from hanspell_break import check

def get_spell_check_data(sent):
    result = check(sent)
    r = result.as_dict()
    return r

def main(wf):
    args = wf.args[0]

    # def wrapper():
    #     return get_spell_check_data(args)

    # res_json = wf.cached_data(args, wrapper, max_age=600)
    end_mark = re.search('\s+$', args)
    if end_mark:
        res_json = get_spell_check_data(args)
        out = f"{res_json['checked']}".rstrip()

        wf.add_item(
            title=out,
            subtitle="Press Enter to paste the results",
            arg=out,
            autocomplete=out,
            valid=True)

        wf.add_item(title=args,
                subtitle="Copy original text",
                autocomplete=args,
                arg=args,
                valid=True)

        wf.send_feedback()
    else:
        wf.logger.debug("args: %s" % args)
        wf.add_item(title=u'Press the spacebar to print the result', valid=False)
        wf.send_feedback()

if __name__ == '__main__':
    wf = Workflow3()
    sys.exit(wf.run(main))

 

Edited by greedist
Link to comment
10 minutes ago, vitor said:

When asking for help with a workflow, please share the workflow itself. It doesn’t seem like the problem is the code but that you have “Argument Required” instead of “Argument Optional” in the object itself.

 

Thank you for your help 🙏

I have corrected the text

Link to comment

Do the change mentioned above:

 

23 hours ago, vitor said:

you have “Argument Required” instead of “Argument Optional” in the object itself.

 

9kq1Ysq.png

 

Two more tips, from a glance:

  • Always prefer with input as argv instead of with input as {query}. There is a reason that’s the default, it doesn’t require custom escaping. In the Script box you use "${1}" instead of "{query}".
  • The python3 … || /usr/bin/python3 … complicates the code but doesn’t offer any benefit. The second part (/usr/bin/python3) will never trigger because /usr/bin/python3 is already matched with python3.

Link to comment
16 minutes ago, vitor said:

Do the change mentioned above:

 

 

9kq1Ysq.png

 

Two more tips, from a glance:

  • Always prefer with input as argv instead of with input as {query}. There is a reason that’s the default, it doesn’t require custom escaping. In the Script box you use "${1}" instead of "{query}".
  • The python3 … || /usr/bin/python3 … complicates the code but doesn’t offer any benefit. The second part (/usr/bin/python3) will never trigger because /usr/bin/python3 is already matched with python3.

 

 

Thank you for your nice advice 😃

Link to comment

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