我试图每分钟向名为“Dbeaver”的 macOS (Mojave) 应用程序发送一次击键(command+shift+r)只要DBeaver 是事件应用程序。我已经尝试过以下方法,但没有效果。
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
if "DBeaver" is in activeApp then
tell application "System Events" to keystroke "r" using {command down, shift down}
end if
end tell
如果脚本像下面这样简单,那么它就可以完美地工作:
activate application "DBeaver"
tell application "System Events" to keystroke "r" using {command down, shift down}
最佳答案
我没有您提到的应用程序,但我使用 TextEdit.app 测试了以下 AppleScript 代码,并且它有效。如果您遇到任何错误或问题,请告诉我
tell application "System Events"
repeat while (exists of application process "DBeaver")
set activeApp to name of first application process whose frontmost is true
if "DBeaver" is in activeApp then
tell its application process "DBeaver"
repeat while frontmost
keystroke "r" using {command down, shift down}
delay 60
end repeat
end tell
end if
end repeat
end tell
关于macOS 定期向事件应用程序发送击键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60268384/