import threading import sys import time from watchfiles import watch import pygetwindow as gw import pyautogui import subprocess from termcolor import colored # ___ _ _ _ ____ ____ # |_ _|_ __ | |_ ___ _ __ ___ ___ _ __ | |_ ___ _ __ / \ | _ \/ ___| # | || '_ \| __/ _ \ '__/ __/ _ \ '_ \| __/ _ \| '__| / _ \ | |_) \___ \ # | || | | | || __/ | | (_| __/ |_) | || (_) | | / ___ \| __/ ___) | # |___|_| |_|\__\___|_| \___\___| .__/ \__\___/|_| /_/ \_\_| |____/ # |_| APS Version Alpha-2 by P7MJ # ---------- Monitor Path ---------- # monitor_path = r"C:\Program Files\Renato Software\Senso.Cloud.Client" # Path to be monitored # ---------- Variables (REMOVE) ---------- # program = "" # 0 is use path, -1 is use name, 1-4 is programs p_name = "" p_path = "" # used only if program = 0. # ---------- Bring to front ---------- # def bring_to_front(window_title): time.sleep(0.5) try: print("Bringing to front...", end = " ") windows = gw.getWindowsWithTitle(window_title) if windows: window = windows[0] window.restore() window.activate() print("Window has been brought to front.") else: print(colored("ERROR: Window not found", 'red')) except Exception as e: print(colored(f"Error: {e}", 'red')) # ---------- File watch ---------- # def file_watch(iftest): print("=" * 80) print("Monitoring changes in " + monitor_path + ".") print("-" * 80) try: if iftest == False: for changes in watch(monitor_path): for change_type, path in changes: print(f"Change type: {change_type}, Path: {path}") return True else: return True except Exception as e: print(colored(f"File Watch Error: {e}", 'red')) # ---------- Minimize ---------- # def minimize(): print("=" * 80) print("Minimizing all windows...", end = " ") pyautogui.hotkey('win', 'd') print("Completed.") # ---------- Launch cover (program) ---------- # def launch_cover(programs): time.sleep(0.5) print("=" * 80) print("Launching cover application...", end = " ") if programs == "1": # Chrome try: subprocess.run( ["C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"] ) print("Launched Chrome.") except Exception as e: print(colored(f"Chrome Launch Error: {e}", 'red')) elif programs == "2": # Edge try: subprocess.run( ["C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"] ) print("Launched Edge.") except Exception as e: print(colored(f"Edge Launch Error: {e}", 'red')) elif programs == "3": # Adobe Illustrator try: subprocess.run( ["C:\\Program Files\\Adobe\\Adobe Illustrator 2025\\Support Files\\Contents\\Windows\\Illustrator.exe"] ) print("Launched Illustrator.") except Exception as e: print(colored(f"Illustrator Launch Error: {e}", 'red')) elif programs == "4": # Onenote try: subprocess.run( ["C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\ONENOTE.EXE"] ) print("Launched OneNote.") except Exception as e: print(colored(f"OneNote Launch Error: {e}", 'red')) else: print(colored("Error: Invalid Cover App Specified.", 'red')) # ---------- Launch cover (program) path ---------- # def launch_cover_path(path): print("Launching custom path...", end = " ") time.sleep(0.5) subprocess.run( [path] ) print("Launched custom path.") # ---------- Specific Chrome tab ---------- # def specific_tab(browser, tab_no): time.sleep(0.5) try: print(f"Bringing browser {browser} to front...", end = " ") windows = gw.getWindowsWithTitle(browser) if windows: window = windows[0] window.restore() window.activate() print(f"{browser} has been brought to front.") print(f"Going to tab {tab_no} in browser...", end = " ") try: pyautogui.hotkey('ctrl', '1') if tab_no == 1: print("Success.") else: for i in range(tab_no - 1): pyautogui.hotkey('ctrl', 'tab') time.sleep(0.1) print("Success.") except Exception as e: print(colored(f"Tab switch error: {e}", 'red')) else: print(colored("ERROR: Window not found", 'red')) except Exception as e: print(colored(f"Specific-Tab Error: {e}", 'red')) # ---------- Help Section ---------- # def help_section(): print() print("- (1): Opens a new, empty window of this program") print("- (2): Opens the window. You have to open the application first and set it up to the desired state to have it work.") print("- (3): Opens an identical but new window of what you already have. The program can be closed, but you must set it up to the desired state before closing it.") print("- (4): Enter a path to the program. This only opens the program and requires you to do research on the program behavior when opened.") print("- (5): Opens the specified Chrome tab. This method is newly developed and is a bit slower to respond, but can precisely open any tab in Chrome.") print("- (6): Specifies a window name. Partial names (wildcards) are default.") print() # ---------- Main ---------- # testmode = False def main(): global testmode while True: print("=" * 80) print(f"Interceptor APS (Active Protection System) Alpha-3| TESTMODE: {testmode}") print("-" * 80) print("Choose a cover app to open:") print("[1] Chrome (note 1)") print("[2] Edge (note 1)") print("[3] Adobe Illustrator (note 2)") print("[4] Onenote (note 3)") print("[5] Enter a path (note 4)") print("[6] Specify Chrome Tab Number (note 5)") print("[7] Specify Window Name (note 6)\n") print("[x] Help (w/notes)") print("[y] Toggle test mode", end = "\n\n") print("[c] Exit") program = input("Enter your option > ") if program.isdigit(): if int(program) >= 1 and int(program) <= 4: print(f"Option {program} selected. Watching...") try: file_watch(testmode) except KeyboardInterrupt: print("User cancelled file watch.") except Exception as e: print(f"File watch error: {e}") minimize() launch_cover(program) if program == "5": # If path is selected (I doubt that) p_path = input("Enter full path >") print("Path selected. Watching...", end = " ") try: file_watch(testmode) except KeyboardInterrupt: print("User cancelled file watch.") except Exception as e: print(f"File watch error: {e}") print("File change detected!") minimize() launch_cover_path(p_path) # VERIFY IF DOUBLE ESCAPES ARE NEEDED WHEN PATH IS FIRST ENTERED BY USER elif program == "6": tabs_no = input("Tab number > ") if tabs_no.isdigit(): print(f"Tab {tabs_no} selected. Watching...", end = " ") try: file_watch(testmode) except KeyboardInterrupt: print("User cancelled file watch.") except Exception as e: print(f"File watch error: {e}") print("File change detected!") minimize() specific_tab("chrome", int(tabs_no)) else: print("Error: Not a digit") pass elif program == "7": # If name is chosen p_name = input("Name of window > ") print(f"Window \"{p_name}\" selected. Watching...", end = " ") try: file_watch(testmode) except KeyboardInterrupt: print("User cancelled file watch.") except Exception as e: print(f"File watch error: {e}") print("File change detected!") minimize() bring_to_front(p_name) else: print(f"Error: Option \"{program}\" selected and passed isdigit() criteria, but did not get selected") elif program.isalpha(): if program.lower() == "x": help_section() elif program.lower() == "y": testmode = not testmode print(f"Test mode set to {testmode}") elif program.lower() == "c": sys.exit(0) else: print(f"Error: Option \"{program}\" selected and passed isalpha() criteria, but did not get selected") else: print("Error: Not an option.") # ---------- Main-main ---------- # if __name__ == "__main__": main()