|
12 | 12 | from ualfred import Workflow3 |
13 | 13 |
|
14 | 14 | WORKFLOW_BASE_FILES = ["info.plist", "workflow_main.py", "__init__.py"] |
15 | | -AFW_ENTRY_POINT_FILE = "afw_entry_point.py" |
16 | | -AFW_REQUIREMENTS = [] |
| 15 | +# AFW_ENTRY_POINT_FILE = "afw_entry_point.py" |
| 16 | +AFW_ENTRY_POINT_FILE = "afw.py" |
| 17 | +AFW_REQUIREMENTS = ["click"] |
17 | 18 |
|
18 | 19 |
|
19 | 20 | @click.group() |
@@ -87,6 +88,49 @@ def build(workflow_path: str): |
87 | 88 | print(f"Create Alfred workflow[{package_path}] finished.") |
88 | 89 |
|
89 | 90 |
|
| 91 | +def main(workflow): |
| 92 | + # The Workflow3 instance will be passed to the function |
| 93 | + # you call from `Workflow3.run`. |
| 94 | + # Not super useful, as the `wf` object created in |
| 95 | + # the `if __name__ ...` clause below is global... |
| 96 | + # |
| 97 | + # Your imports go here if you want to catch import errors, which |
| 98 | + # is not a bad idea, or if the modules/packages are in a directory |
| 99 | + # added via `Workflow3(libraries=...)` |
| 100 | + # import somemodule |
| 101 | + # import anothermodule |
| 102 | + |
| 103 | + # Get args from Workflow3, already in normalized Unicode. |
| 104 | + # This is also necessary for "magic" arguments to work. |
| 105 | + # args = wf.args |
| 106 | + |
| 107 | + # Do stuff here ... |
| 108 | + from workflow_main import call_workflow |
| 109 | + |
| 110 | + feedback = call_workflow(workflow) |
| 111 | + |
| 112 | + # Add an item to Alfred feedback |
| 113 | + # wf.add_item(u'Item title', u'Item subtitle') |
| 114 | + for item in feedback: |
| 115 | + workflow.add_item(**item) |
| 116 | + |
| 117 | + # Send output to Alfred. You can only call this once. |
| 118 | + # Well, you *can* call it multiple times, but subsequent calls |
| 119 | + # are ignored (otherwise the JSON sent to Alfred would be invalid). |
| 120 | + workflow.send_feedback() |
| 121 | + |
| 122 | + |
| 123 | +@cli.command() |
| 124 | +@click.argument("query") |
| 125 | +def call(query): |
| 126 | + # Create a global `Workflow3` object |
| 127 | + wf = Workflow3() |
| 128 | + # Call your entry function via `Workflow3.run()` to enable its |
| 129 | + # helper functions, like exception catching, ARGV normalization, |
| 130 | + # magic arguments etc. |
| 131 | + sys.exit(wf.run(main)) |
| 132 | + |
| 133 | + |
90 | 134 | @cli.command() |
91 | 135 | @click.argument("workflow_path") |
92 | 136 | @click.argument("query") |
|
0 commit comments