Is there a way to know if ui.vision has been paused or to directly pause the script through code?

import sys
import os
import datetime
import subprocess
import time

def PlayAndWait(macro, timeout_seconds=10, var1=‘-’, var2=‘-’, var3=‘-’, path_downloaddir=None, path_autorun_html=None,
browser_path=None):
assert os.path.exists(path_downloaddir)
assert os.path.exists(path_autorun_html)
assert os.path.exists(browser_path)

log = 'KeWei_log_' + datetime.datetime.now().strftime('%m-%d-%Y_%H_%M_%S') + '.txt'
path_log = os.path.join(path_downloaddir, log)

args = r'file:///' + path_autorun_html + '?macro=' + macro + '&cmd_var1=' + var1 + '&cmd_var2=' + var2 + '&cmd_var3=' + var3 + '&closeRPA=1&direct=1&savelog=' + log

proc = subprocess.Popen([browser_path, args])

status_runtime = 0

print("Log File will show up at " + path_log)

while (not os.path.exists(path_log) and status_runtime < timeout_seconds):
    print("Waiting for macro to complete, seconds=%d" % status_runtime)
    time.sleep(1)
    status_runtime += 1

if status_runtime < timeout_seconds:
    with open(path_log, 'r', encoding='utf-8') as f:
        status_text = f.readline()

    if status_text.find('Status=OK') != -1:
        status_init = 1
    else:
        status_init = -1
        # Restart the script file of path_autorun_html
        subprocess.Popen([browser_path, path_autorun_html])
        sys.exit("Did not find 'Status=OK' in the log, the script has stopped and restarted the script file.")
else:
    status_text = "Macro did not complete within the given time: %d" % timeout_seconds
    status_init = -2
    proc.kill()

print(status_text)
return status_init  # Return status instead of exiting the program

def clean_old_logs(path_downloader):
# Get the current time
now = datetime.datetime.now()
# Calculate the time one week ago
one_week_ago = now - datetime.timedelta(days=2)
# List all files in the download directory
for filename in os.listdir(path_downloader):
file_path = os.path.join(path_downloader, filename)
# Check if the file is a regular file and if it is older than one week
if os.path.isfile(file_path) and os.path.getmtime(file_path) < one_week_ago.timestamp():
print(f"Deleting old log file: {file_path}")
os.remove(file_path)

def check_time(start_hour, start_minute, end_hour, end_minute):
now = datetime.datetime.now()
start_time = datetime.time(start_hour, start_minute)
end_time = datetime.time(end_hour, end_minute)
if start_time <= now.time() < end_time:
return True
return False

if name == ‘main’:
logFilePath = r’C:\Users\wh\Downloads’
while True:
if check_time(8, 0, 13, 0): # Run from 8:00 to 12:00
clean_old_logs(logFilePath) # Clean up old logs before running the macro
status = PlayAndWait(
‘KeWeiAppliances/grabOutboundWorkOrders’,
timeout_seconds=1500,
path_downloaddir=logFilePath,
path_autorun_html=r’d:\ui.vision.html’,
browser_path=r’C:\Users\wh\AppData\Local\Google\Chrome\Application\chrome.exe’
)
print(f"Waiting 80 seconds before launching!“)
time.sleep(80) # Wait for 1 minute, then check the time again
elif check_time(13, 20, 20, 15): # Run from 13:30 to 20:30
clean_old_logs(logFilePath) # Clean up old logs before running the macro
status = PlayAndWait(
‘KeWeiAppliances/grabOutboundWorkOrders’,
timeout_seconds=1500,
path_downloaddir=logFilePath,
path_autorun_html=r’d:\ui.vision.html’,
browser_path=r’C:\Users\wh\AppData\Local\Google\Chrome\Application\chrome.exe’
)
print(f"Waiting 80 seconds before launching!”)
time.sleep(80) # Wait for 1 minute, then check the time again
else:
print(“Current time is not within the scheduled runtime. Waiting…”)
time.sleep(60) # Wait for 1 minute, then check the time again