【问题标题】:Automator keystroke not working with Zero digitAutomator 击键不适用于零位
【发布时间】:2017-03-16 15:16:45
【问题描述】:

我有一个自动化脚本,它应该让浏览器全屏显示并使用 command + 0 将其缩放回默认大小。全屏可以工作,但带有 0 的按键被忽略。

tell application "System Events"
    keystroke "f" using {command down, control down}        
    keystroke "0" using {command down}
end tell

我试过了:

 keystroke "0" using {command down}
 keystroke 0 using {command down}
 keystroke {29} using {command down}

全部忽略。

【问题讨论】:

  • 在告诉系统事件之后和击键之前,您必须告诉您的浏览器并使其激活。然后按键将按预期发送到您的浏览器。
  • 你的意思是返回输入。是的,我有。这只是脚本的告诉部分。 command+F 执行,但 command+0 不执行
  • 你的浏览器是什么,command+0应该做什么? (我试过 Safari,但是 command+0 什么也没做)

标签: applescript automator


【解决方案1】:

我将重申 pbell 所说的并提供 Finder 的工作代码,因为我不确定您的特定应用程序是如何工作的:

tell application "System Events"
   tell application "Finder" to activate
   keystroke "f" using {command down, control down}
   delay 1
   keystroke "f" using {command down, control down}
end tell

其中重要的部分是我们首先激活了 Finder,因此击键被发送到正确的应用程序。

同样重要的是,根据用例,在“系统偏好设置”->“安全和隐私”->“隐私”->“辅助功能”中为您的应用程序启用辅助功能权限

【讨论】:

    【解决方案2】:

    听起来像是时间问题。 (埃里克和我写这篇文章的想法一样!):)

    您可以添加延迟:

    tell application "Safari" to activate
    tell application "System Events"
        tell process "Safari"
            keystroke "f" using {command down, control down}
            delay 1
            keystroke "0" using {command down}
        end tell
    end tell
    

    但在我的测试中,你也可以颠倒操作顺序。它会起作用并且不需要延迟。

    tell application "Safari" to activate
    tell application "System Events"
        tell process "Safari"
            keystroke "0" using {command down}
            keystroke "f" using {command down, control down}
        end tell
    end tell
    

    【讨论】:

      猜你喜欢
      • 2015-09-26
      • 2022-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-22
      • 1970-01-01
      • 1970-01-01
      • 2014-07-03
      相关资源
      最近更新 更多