点击 applescript
Click with applescript
我正在尝试在屏幕的特定位置自动点击。我找到了几个问题的答案,但其中 none 个对我有帮助。
这个命令应该验证"Spotify"(这是一个随机应用程序,只是为了做一个测试)是否在最前面。如果是这样,它应该点击屏幕的某个位置(在这种情况下,鼠标的位置在 "play" 按钮上)。
我运行这个程序,一切正常。但是当我把应用程序放在前台时,什么也没有发生。程序以 "Result: 1"
结束
set x to 0
repeat until x is equal to 1
tell application "System Events"
if frontmost of application "Spotify" is true then
delay (2)
tell application "System Events"
click at {720, 634}
end tell
set x to 1
end if
end tell
end repeat
我也试过放一些"delay",但是没用
找到替代方法:使用 python。
要安装 python,只需上网冲浪,您就会知道如何安装。
我使用的库是"pyAutoGui"。
要安装它,请看这里:
https://pyautogui.readthedocs.io/en/latest/install.html
然后,如果你想在 automator 上使用 python 和这个库,请按此操作。
- 打开自动程序
- 在菜单中查找"Run Shell Script"
- 在 "Shell" 选项上,select “/bin/bash”
然后,如果您想 运行 您的程序带有第三方库,请复制它
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7<< "EOF"
插入你的python程序然后在最后写"EOF"
举个小例子
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7<< "EOF"
import pyautogui
pyautogui.click(720, 634)
EOF
我正在尝试在屏幕的特定位置自动点击。我找到了几个问题的答案,但其中 none 个对我有帮助。
这个命令应该验证"Spotify"(这是一个随机应用程序,只是为了做一个测试)是否在最前面。如果是这样,它应该点击屏幕的某个位置(在这种情况下,鼠标的位置在 "play" 按钮上)。 我运行这个程序,一切正常。但是当我把应用程序放在前台时,什么也没有发生。程序以 "Result: 1"
结束set x to 0
repeat until x is equal to 1
tell application "System Events"
if frontmost of application "Spotify" is true then
delay (2)
tell application "System Events"
click at {720, 634}
end tell
set x to 1
end if
end tell
end repeat
我也试过放一些"delay",但是没用
找到替代方法:使用 python。
要安装 python,只需上网冲浪,您就会知道如何安装。
我使用的库是"pyAutoGui"。 要安装它,请看这里: https://pyautogui.readthedocs.io/en/latest/install.html
然后,如果你想在 automator 上使用 python 和这个库,请按此操作。
- 打开自动程序
- 在菜单中查找"Run Shell Script"
- 在 "Shell" 选项上,select “/bin/bash”
然后,如果您想 运行 您的程序带有第三方库,请复制它
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7<< "EOF"
插入你的python程序然后在最后写"EOF"
举个小例子
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7<< "EOF"
import pyautogui
pyautogui.click(720, 634)
EOF