尝试模仿点击和拖动动作从一个屏幕位置到另一个脚本位置,如下所示:
my mouseDrag(100, 200, 499, 400, 1) -- EDIT here 2 positions and the delay
on mouseDrag(xDown, yDown, xUp, yUp, delayTime)
-- delayTime because the drag may fail if the UI isn't fast enough without a delay. For what I do, .1 works.
do shell script "/usr/bin/python <<END
from Quartz.CoreGraphics import CGEventCreateMouseEvent
from Quartz.CoreGraphics import CGEventCreate
from Quartz.CoreGraphics import CGEventPost
from Quartz.CoreGraphics import kCGEventLeftMouseDown
from Quartz.CoreGraphics import kCGEventLeftMouseUp
from Quartz.CoreGraphics import kCGMouseButtonLeft
from Quartz.CoreGraphics import kCGHIDEventTap
from Quartz.CoreGraphics import kCGEventLeftMouseDragged
import time
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy);
def mousedrag(posx,posy):
mouseEvent(kCGEventLeftMouseDragged, posx,posy);
def mousedown(posxdown,posydown):
mouseEvent(kCGEventLeftMouseDown, posxdown,posydown);
def mouseup(posxup,posyup):
mouseEvent(kCGEventLeftMouseUp, posxup,posyup);
ourEvent = CGEventCreate(None);
mousedown(" & xDown & "," & yDown & ");
time.sleep(" & (delayTime as text) & "); mousedrag(" & xUp & "," & yUp & ");
time.sleep(" & (delayTime as text) & "); mouseup(" & xUp & "," & yUp & ");
END"
end mouseDrag