Batch Mode
Batch mode allows automated execution of tasks on specific applications or files using predefined plan files. This mode is particularly useful for repetitive tasks on Microsoft Office applications (Word, Excel, PowerPoint).
Quick Start
Step 1: Create a Plan File
Create a JSON plan file that defines the task to be automated. The plan file should contain the following fields:
| Field | Description | Type |
|---|---|---|
| task | The task description. | String |
| object | The application or file to interact with. | String |
| close | Determines whether to close the corresponding application or file after completing the task. | Boolean |
Example plan file:
{
"task": "Type in a text of 'Test For Fun' with heading 1 level",
"object": "draft.docx",
"close": false
}
Important: The close field should be a boolean value (true or false), not a Python boolean (True or False).
The file structure should be organized as follows:
Parent/
├── tasks/
│ └── plan.json
└── files/
└── draft.docx
The object field in the plan file refers to files in the files directory. The plan reader will automatically resolve the full file path by replacing tasks with files in the directory structure.
Step 2: Start Batch Mode
Run the following command to start batch mode:
# Assume you are in the cloned UFO folder
python -m ufo --task {task_name} --mode batch_normal --plan {plan_file}
Parameters:
- {task_name}: Name for this task execution (used for logging)
- {plan_file}: Full path to the plan JSON file (e.g., C:/Parent/tasks/plan.json)
Supported Applications
Batch mode currently supports the following Microsoft Office applications:
- Word (
.docxfiles) -WINWORD.EXE - Excel (
.xlsxfiles) -EXCEL.EXE - PowerPoint (
.pptxfiles) -POWERPNT.EXE
The application will be automatically launched when the batch mode starts, and the specified file will be opened and maximized.
Evaluation
UFO can automatically evaluate whether the task was completed successfully. To enable evaluation, ensure EVA_SESSION is set to True in the config/ufo/system.yaml file.
Check the evaluation results in logs/{task_name}/evaluation.log.
References
The batch mode uses a PlanReader to parse the plan file and creates a FromFileSession to execute the plan.
PlanReader
The PlanReader is located at ufo/module/sessions/plan_reader.py.
The reader for a plan file.
Initialize a plan reader.
| Parameters: |
|
|---|
Source code in module/sessions/plan_reader.py
18 19 20 21 22 23 24 25 26 27 28 | |
get_close()
Check if the plan is closed.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
30 31 32 33 34 35 36 | |
get_host_agent_request()
Get the request for the host agent.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
get_host_request()
Get the request for the host agent.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
get_initial_request()
Get the initial request in the plan.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
62 63 64 65 66 67 68 69 70 71 72 73 | |
get_operation_object()
Get the operation object in the step.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
54 55 56 57 58 59 60 | |
get_root_path()
Get the root path of the plan.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
148 149 150 151 152 153 154 | |
get_steps()
Get the steps in the plan.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
46 47 48 49 50 51 52 | |
get_support_apps()
Get the support apps in the plan.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
103 104 105 106 107 108 109 | |
get_task()
Get the task name.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
38 39 40 41 42 43 44 | |
next_step()
Get the next step in the plan.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
128 129 130 131 132 133 134 135 136 137 138 | |
task_finished()
Check if the task is finished.
| Returns: |
|
|---|
Source code in module/sessions/plan_reader.py
140 141 142 143 144 145 146 | |
FromFileSession
The FromFileSession is located at ufo/module/sessions/session.py.
Bases: WindowsBaseSession
A session for UFO from files on Windows.
Initialize a session.
| Parameters: |
|
|---|
Source code in module/sessions/session.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
create_new_round()
Create a new round.
Source code in module/sessions/session.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
get_app_com(object_name)
Get the COM object name based on the object name.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in module/sessions/session.py
344 345 346 347 348 349 350 351 352 353 354 355 356 | |
get_app_name(object_name)
Get the application name based on the object name.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Source code in module/sessions/session.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
next_request()
Get the request for the host agent.
| Returns: |
|
|---|
Source code in module/sessions/session.py
315 316 317 318 319 320 321 322 323 324 325 326 | |
record_task_done()
Record the task done.
Source code in module/sessions/session.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |
request_to_evaluate()
Get the request to evaluate. return: The request(s) to evaluate.
Source code in module/sessions/session.py
420 421 422 423 424 425 | |
run()
Run the session.
Source code in module/sessions/session.py
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
setup_application_environment()
Sets up the application environment by determining the application name and command based on the operation object, and then launching the application.
Raises: Exception: If an error occurs during the execution of the command or while interacting with the application via COM.
Source code in module/sessions/session.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
terminate_application_processes()
Terminates specific application processes based on the provided conditions.
Source code in module/sessions/session.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 | |