import pyautogui as ag
from pyautogui import ImageNotFoundException
import pyperclip as cp
ag.PAUSE = 1
ag.FAILSAFE = True
def getImageCenterPosition(image, confidence = 0.7):
screen = ag.screenshot()
try:
result = ag.locate(image, screen, confidence=confidence)
except ImageNotFoundException:
return 0, 0
left, top, width, height = result
x = left / 2 + width / 4
y = top / 2 + height / 4
return x, y
def enterApp(app):
cp.copy(app)
ag.hotkey('Command', 'Tab')
ag.hotkey('Command', 'Space')
ag.hotkey('Command', 'a')
ag.hotkey('Command', 'v')
ag.press('Enter')