如何使用 AppleScript 在 Safari 中实现屏幕点击?

发布于 2024-10-21 17:14:43 字数 495 浏览 2 评论 0原文

我正在尝试创建一个脚本来单击特定的游戏“水晶骑士” 然后单击“将所有礼物排队”

while loop forever

then click "accept"
then do keyboard command "command w"
then wait 5 seconds

我正在使用 AppleScript,这就是我到目前为止所拥有的:

tell application "Safari"
    activate
    open location "http://apps.facebook.com/gfriendfinder/?ref=bookmarks&count=0"
    delay 5
    tell application "System Events"
        click at {750, 550}
    end tell
end tell

我不确定为什么单击功能不起作用。它在正确的地方吗?

I am trying to create a script that will click on the specific game "knights of the crystals"
then click "Queue all Gifts"

while loop forever

then click "accept"
then do keyboard command "command w"
then wait 5 seconds

I am using AppleScript and this is what I have so far:

tell application "Safari"
    activate
    open location "http://apps.facebook.com/gfriendfinder/?ref=bookmarks&count=0"
    delay 5
    tell application "System Events"
        click at {750, 550}
    end tell
end tell

I'm not sure why the click at function is not working. Is it in the right place?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ぃ弥猫深巷。 2024-10-28 17:14:43

首先,这是一种不好的形式,并且可能会因为在不需要时将一个告诉块置于另一个告诉块内而导致问题。例如,您告诉 safari 告诉系统事件点击,而您不需要 safari 这样做。 “打开位置”命令或“延迟”命令甚至不需要 Safari。因此,一般来说,如果不需要,不要告诉应用程序执行某些操作。其次,我发现执行点击对于系统事件多次不起作用。我开发了一个鼠标单击命令行工具,可以在发生这种情况时使用。您可以在此处获取它。下载该文件并将其放在桌面上,然后运行此脚本并查看是否有帮助。

set mouseToolsPath to (path to desktop as text) & "MouseTools"
open location "http://apps.facebook.com/gfriendfinder/?ref=bookmarks&count=0"
delay 5
tell application "Safari" to activate
do shell script quoted form of POSIX path of mouseToolsPath & " -x 750 -y 550 -leftClick"

另一种想法是学习 javascript,因为 Safari 可以理解 javascript,并且您可以用它来按下 Safari 网页中的按钮。我不是 javascript 专家,所以我无能为力。

First, it's bad form and could cause issues by having one tell block inside of another when it's not needed. For example you are telling safari to tell system events to click, when you don't need to have safari do that. Safari is not even required for the "open location" command or the "delay" command. So in general do not tell an application to do something if it's not required. Second, I have found that performing clicks doesn't work many times with system events. I have developed a mouse-clicking command line tool to use when that happens. You can get it here. Download that and place it on your desktop, then run this script and see if that helps.

set mouseToolsPath to (path to desktop as text) & "MouseTools"
open location "http://apps.facebook.com/gfriendfinder/?ref=bookmarks&count=0"
delay 5
tell application "Safari" to activate
do shell script quoted form of POSIX path of mouseToolsPath & " -x 750 -y 550 -leftClick"

One other idea would be to learn javascript, because Safari understands javascript and you can probably press the buttons in a Safari web page with that. I'm not a javascript expert though so I can't help with that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文