Last active
November 20, 2023 09:48
-
-
Save sreejithpro/8ae98130b59b2ba71da8ae7d995af794 to your computer and use it in GitHub Desktop.
An experiment using PyAutoGUI to automate windows actions. This code opens an ALP files, delete results, analyze results, click all results and take a PDF print out
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
import pyautogui | |
def count_files(folder_path): | |
return sum(file.endswith('.alw') and not file.startswith('~$') for file in os.listdir(folder_path)) | |
# Path to the file you want to open | |
directory_path = r"Source ALP Files Folder" | |
save_path = r'Save PDF Folder' | |
total_files = count_files(directory_path) | |
processed_files = 0 | |
start_time = time.time() | |
for filename in os.listdir(directory_path): | |
# Check if the file is an .alw file | |
if filename.endswith('.alw'): | |
# Construct full file path | |
file_path = os.path.join(directory_path, filename) | |
basename = os.path.basename(file_path) | |
filename = os.path.splitext(basename)[0] | |
os.startfile(file_path) | |
# Wait for the application to open the file | |
time.sleep(6) | |
delete_menu_x, delete_menu_y = 4558, 88 # Run MousePos.py and hover over delete results Button to get cordinates for your screen in the console. | |
analyze_menu_x, analyze_menu_y = 4453, 121 # Analyze Button cordinates | |
proceed_menu_x, proceed_menu_y = 3885, 584 # Proceed Button cordinates | |
allresults_x, allresults_y = 3352, 272 # All Results Menu cordinates | |
pyautogui.click(delete_menu_x, delete_menu_y) | |
time.sleep(1) # Change all time.sleep duration to match your computers processing time. | |
pyautogui.click(analyze_menu_x, analyze_menu_y) | |
time.sleep(1) | |
pyautogui.click(proceed_menu_x, proceed_menu_y) | |
time.sleep(1) | |
pyautogui.click(proceed_menu_x, proceed_menu_y) | |
time.sleep(1) | |
pyautogui.doubleClick(allresults_x, allresults_y) | |
time.sleep(1) | |
pyautogui.hotkey('ctrl', 'p') | |
time.sleep(1) | |
pyautogui.press('enter') #This might not work if your default printer is not 'Print To PDF' | |
pyautogui.write(save_path) | |
time.sleep(1) | |
# Press Enter to save the file | |
pyautogui.press('enter') | |
time.sleep(1) | |
pyautogui.hotkey('ctrl', 'a') | |
pyautogui.press('backspace') | |
pyautogui.write(filename) | |
time.sleep(1) | |
pyautogui.press('enter') | |
time.sleep(5) # Printo to PDF time. Can take longer for complex analysis files. Change time.sleep duration to match your computers processing time. | |
close_x, close_y = 5721, 19 # Close button cordinates | |
pyautogui.click(close_x, close_y) | |
pyautogui.press('enter') | |
processed_files += 1 | |
print(f"Processed {processed_files} of {total_files} files.") | |
end_time = time.time() | |
elapsed_time = (end_time - start_time) / 60 | |
print(f"All specified sheets have been printed. Total time taken: {elapsed_time:.2f} minutes") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyautogui | |
import time | |
while True: | |
print(pyautogui.position()) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment