macos - macOS 定期向活动应用发送击键
问题描述
只要DBeaver 是活动应用程序,我正尝试每分钟向名为“Dbeaver”的 macOS (Mojave) 应用程序发送一次击键(command+ shift+ r) 。我试过以下没有效果。
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
推荐阅读
- python - 将 fit_generator 与连体网络一起使用时出错
- reactjs - 如何在reactjs中动态设置谷歌方向api的旅行模式?
- python - 无法从 Morningstar 抓取 dataid - 如何从 Python 访问网络检查工具?
- c++ - 如何使 const 可变 lambda 捕获列表的某些成员?
- ruby - 如何在不读取 HTTP 资源的其余部分的情况下读取标头?
- matlab - 条形图 x 轴 Matlab
- r - 是否有与 Panda 的 to_datetime 类似的 R 方法?Char 到 POSIXct 问题
- oracle - 如何在 Oracle 中计算多重回归
- mysql - 我正在处理查询,当有活动时,我要计算日期,如果日期范围内没有活动,我也想得到计数 0
- c - C用下一个和前一个指针创建一个链表