如何在AppleScript上执行其他任务时单击后台应用程序?

时间:2014-07-26 09:52:47

标签: macos applescript

好的,所以我尝试制作一个每隔一段时间点击一个固定点的AppleScript。问题是我无法弄清楚如何在后台使用脚本而不会干扰其他应用程序。我不能用GUI编写脚本,因为我编写的脚本是用Java编写的。

1 个答案:

答案 0 :(得分:0)

Applescript不会这么做,但可以使用从Apple开发的其他语言来完成,比如Python:

set x to 30
set y to 5
set l to 50 -- click same location 50 times

do shell script "
/usr/bin/python <<END
import sys
import time
from Quartz.CoreGraphics import *
def mouseEvent(type, posx, posy):
theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
CGEventPost(kCGHIDEventTap, theEvent)
def mousemove(posx,posy):
mouseEvent(kCGEventMouseMoved, posx,posy);
def mouseclick(posx,posy):
mouseEvent(kCGEventLeftMouseDown, posx,posy);
mouseEvent(kCGEventLeftMouseUp, posx,posy);
ourEvent = CGEventCreate(None);
currentpos=CGEventGetLocation(ourEvent);             # Save current mouse position
for x in range(0, " & l & "):
          mouseclick(" & x & "," & y & ");
mousemove(int(currentpos.x),int(currentpos.y));      # Restore mouse position
END"

More info here