99 lines
3.4 KiB
Python
99 lines
3.4 KiB
Python
#!/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 project root
|
|
if 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()
|