macOS 定期向事件应用程序发送击键

标签 macos applescript macos-mojave osascript

我试图每分钟向名为“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/

相关文章:

通过 Mac Ports 在 Mac OSX 上使用 Ruby

python - psycopg2、pymc、theano 和 DYLD_FALLBACK_LIBRARY_PATH

fonts - macOS Mojave上Safari 12中的字体系列/显示问题

ruby-on-rails - 安装 nokogiri (1.6.6.2) 时出错,Bundler 无法继续

objective-c - 检查 NSNumber 是否为小数

macos - 对现有OSX应用进行沙箱

macos - 以编程方式在 TextEdit 中选择文本范围

cocoa - NSTask 启动导致崩溃

stream - 在 OSX 上通过 AppleScript 使用 iTunes 打开 URL

c++ - Code::Blocks C++ 使用 MacOS Mojave 编译: fatal error :sys/cdefs.h:没有这样的文件或目录