#!/usr/bin/env python3 """ Diagnostic script to test PyAutoGUI permissions and functionality Run this both from VS Code and from the built app to compare behavior """ import sys import os # Add src directory to path when run from tests folder if os.path.exists('../src'): sys.path.insert(0, '../src') elif os.path.exists('src'): sys.path.insert(0, 'src') def test_pyautogui_permissions(): """Test PyAutoGUI functionality and permissions""" print("šŸ” PyAutoGUI Permissions Diagnostic") print("=====================================") try: import pyautogui print("āœ… PyAutoGUI imported successfully") except ImportError as e: print(f"āŒ Failed to import PyAutoGUI: {e}") return # Test 1: Get mouse position print("\nšŸ“ Test 1: Getting mouse position") try: x, y = pyautogui.position() print(f"āœ… Current mouse position: ({x}, {y})") except Exception as e: print(f"āŒ Failed to get mouse position: {e}") print(" This indicates accessibility permission issues") return # Test 2: Screen size print("\nšŸ“ Test 2: Getting screen size") try: width, height = pyautogui.size() print(f"āœ… Screen size: {width}x{height}") except Exception as e: print(f"āŒ Failed to get screen size: {e}") # Test 3: Small mouse movement print("\n🐭 Test 3: Small mouse movement") try: original_x, original_y = pyautogui.position() print(f"Original position: ({original_x}, {original_y})") # Move mouse 1 pixel pyautogui.moveRel(1, 0, duration=0.1) new_x, new_y = pyautogui.position() print(f"After move: ({new_x}, {new_y})") # Move back pyautogui.moveRel(-1, 0, duration=0.1) final_x, final_y = pyautogui.position() print(f"After return: ({final_x}, {final_y})") if new_x != original_x or new_y != original_y: print("āœ… Mouse movement successful!") else: print("āŒ Mouse movement failed - position didn't change") print(" This indicates the app doesn't have permission to control the mouse") except Exception as e: print(f"āŒ Failed to move mouse: {e}") print(" This indicates accessibility permission issues") # Test 4: Key press print("\nāŒØļø Test 4: Key press (F15)") try: pyautogui.press('f15') print("āœ… Key press successful (F15 sent)") except Exception as e: print(f"āŒ Failed to send key press: {e}") # Test 5: Check running environment print("\nšŸ”§ Test 5: Environment information") print(f"Python executable: {sys.executable}") print(f"Running from: {os.getcwd()}") print(f"Script path: {__file__ if '__file__' in globals() else 'Unknown'}") if getattr(sys, 'frozen', False): print("šŸŽ Running as PyInstaller bundle") print(f"Bundle path: {sys._MEIPASS}") else: print("šŸ Running as Python script") # Test 6: Recommendations print("\nšŸ’” Recommendations:") print("1. Check System Preferences > Privacy & Security > Accessibility") print("2. Ensure the app (or Terminal/VS Code) has accessibility permissions") print("3. If running from built app, try self-signing:") print(" codesign --force --deep --sign - /path/to/HereIAm.app") print("4. Check Console.app for any security-related error messages") if __name__ == "__main__": test_pyautogui_permissions()