Automation with Python

To move a mouse pointer have been done in many different ways.
To do it in Python why not. Its not about speed its about doing it in Python. :slight_smile:

Few examples of this package, this approach is only to show do shell script and python in AS.
https://pyautogui.readthedocs.io/en/latest/index.html

Its works for Python 2 or 3
pip install pyautogui to install the package to be able to run the script below.

Comment out ## to try all exemples.

(**
* Python library to do automation tasks for (Python 2 or 3)
*
* pip install pyautogui
*)

set theScript to "
import pyautogui
import time

##print(pyautogui.size()) # size of the screen in width and height
##width, height = pyautogui.size()
##print('Width is',width, 'points')
##print('Height is',height, 'points')

time.sleep(1) # sleep for 1 second

##print(pyautogui.position()) # mouse position in x, y position
##x, y = pyautogui.position()
##print('Current x-pos is',x,'points')
##print('Current y-pos is',y,'points')

##pyautogui.moveTo(50,50) # move the mouse pointer to x, y position
##x, y = pyautogui.position()
##print('Start x-pos is',x,'points')
##print('Start y-pos is',y,'points')

# Same as above with time from start to end position
##pyautogui.moveTo(400,400,3)
##x, y = pyautogui.position()
##print('Move to x-pos',x,'points in 3 second motion')
##print('Move to y-pos',y,'points in 3 second motion')

# click at Apple icon in menubar and do 3 second motion
pyautogui.moveTo(25,10,3)
pyautogui.click()
##pyautogui.click(25,10) # click at Apple icon in menubar with x, y position

# Script Editor hotkey to preferences...
##pyautogui.hotkey('command',',')
"
do shell script "/usr/local/bin/python3 <<EOF " & theScript

To draw a rectangle shape in ex. Pixelmator you could add this code.
The mouse position x, y top left in clock wise order

# To draw freeform in Pixelmator (could be any application that could draw)
pyautogui.dragRel(100, 0, button='left')
pyautogui.dragRel(0, 100, button='left')
pyautogui.dragRel(-100, 0, button='left')
pyautogui.dragRel(0, -100, button='left')