I tried to click the icon in the Dock of MacBook Pro (15-inch, 2018) with Python + PyAutoGUI, but when I wrote this code, it didn't work.
click.py
import pyautogui as pag
position = pag.locateCenterOnScreen('target_app.png', confidence=0.9)
pag.click(position)
The Dock snaps for a moment and the target application doesn't start.
When I checked the coordinates of the icon position of the Dock, I noticed that the value obtained by locateCenterOnScreen and the value obtained by hovering the mouse over the icon and position () are completely different.
** Value obtained by locateCenterOnScreen **
x=3046, y=2335
** Mouse cursor value obtained with pyautogui.position () **
x=1517, y=1169
Since both x and y are about half the values, I thought that the resolution of the Retina display was related, so I passed the values obtained by halving each to click ().
click.py
import pyautogui as pag
x,y = pag.locateCenterOnScreen('target_app.png', confidence=0.9)
pag.click(x/2, y/2)
bingo. You can now click the icon on the Dock to launch the application.