【问题标题】:Applescript or Automator behaves differently at night?Applescript 或 Automator 在晚上的行为不同?
【发布时间】:2020-11-06 13:49:47
【问题描述】:

我有一个简单的 Automator 应用程序,可以在午夜启动一个应用程序,然后是 automator 工作流程,在早上 6 点退出。两者都贯穿日历。启动工作正常。我在戒烟时遇到问题,但仅限于晚上。

如果我现在运行退出脚本,它可以正常工作。如果我通过将日历设置为几分钟后运行脚本,它可以正常工作。但是设置为早上 6 点,我早上检查,它没有工作。

我的系统是 Mac Mini macOS Catalina。该应用程序是 Bittorent Web。 Bittorrent Web 启动一个小应用程序,然后启动 Safari。因此,对于我的“退出”工作流程,我首先使用 Automator 功能退出 Safari。接下来我使用脚本退出 Bittorrent,因为 Bittorrent 会询问您是否确定要退出。该脚本将 bittorent 置于最前面,运行 command-q,然后返回。这部分在晚上不起作用。

机器设置为不休眠。 automator 和 automator 应用程序具有运行脚本的完全权限 - 正如我所说,如果我现在运行它,它会工作。所以我迷路了。脚本是;

on run {input, parameters}
  tell application "System Events"
    set frontmost of process "BitTorrent Web" to true
     keystroke "q" using command down
     keystroke return
  end tell
end run

希望这是有道理的。正如我所说,这现在有效,但在早上我发现 Safari 已关闭,但 BitTorrent 仍在运行 - 没有错误,并且“你是否真的要退出”对话框也不是他们的。谢谢

【问题讨论】:

    标签: macos applescript macos-catalina automator


    【解决方案1】:

    更好更可靠的方法是

    on run {input, parameters}
      if application "BitTorrent Web" is running then quit application "BitTorrent Web"
    end run
    

    或者显式寻址进程(进程名称可能不同)

    on run {input, parameters}
      activate application “BitTorrent Web”
      tell application "System Events"
         tell process “BitTorrent Web”
             keystroke "q" using command down
             keystroke return
         end tell
      end tell
    end run
    

    【讨论】:

    • 谢谢。因此,当应用程序弹出“我真的要退出”对话框时,我是否应该在“结束运行”之前的行中添加“击键返回”?
    • 哦,不知道有请求。你不能禁用它吗?您可以尝试使用系统事件发送返回,但您可能会遇到同样的问题,即应用程序目前不在最前面。
    • 好的,谢谢。我会试试的。它现在可以工作,但会在一夜之间通过日历事件对其进行测试。
    猜你喜欢
    • 1970-01-01
    • 2021-08-22
    • 1970-01-01
    • 1970-01-01
    • 2013-10-12
    • 2014-03-25
    • 2011-12-28
    • 1970-01-01
    • 2011-01-07
    相关资源
    最近更新 更多