From 72b8b390768ae7b799ac68829440db443b83ae2a Mon Sep 17 00:00:00 2001 From: Emi Date: Sat, 5 Jul 2025 23:21:38 -0300 Subject: [PATCH] fix error on browser location error --- script.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/script.py b/script.py index d2c6728..e9264c1 100644 --- a/script.py +++ b/script.py @@ -23,15 +23,15 @@ listener.start() # Enter the name of your browser, based on the name of its icon image. browser_img = 'brave.png' +try: + browser_loc = pgui.locateCenterOnScreen(f'img/{browser_img}', confidence=0.8) -browser_loc = pgui.locateCenterOnScreen(f'img/{browser_img}', confidence=0.8) - -if browser_loc: - pgui.moveTo(browser_loc, duration=0.2) - pgui.click() - # Change the time depending on how long it takes to open your browser - time.sleep(2) -else: + if browser_loc: + pgui.moveTo(browser_loc, duration=0.2) + pgui.click() + # Change the time depending on how long it takes to open your browser + time.sleep(2) +except (pgui.ImageNotFoundException, Exception): print("Browser icon not found.") sys.exit('closing script')