2017-03-15 61 views
0

我有一个automator脚本,它应该使浏览器全屏显示,并使用命令+ 0将其缩回到默认大小。全屏工作,但忽略带有0的按键。Automator keystroke不能用于零数字

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} 

所有被忽略。

+0

在告诉系统事件和按键之前,您必须告诉您的浏览器并将其激活。然后击键将按预期发送到您的浏览器。 – pbell

+0

你的意思是返回输入。是的,我有。这只是告诉脚本的一部分。命令+ F执行,但不执行命令+ 0 – Omar

+0

什么是浏览器和命令+ 0应该执行什么操作? (我试过Safari,但是命令+ 0什么都不做) – pbell

回答

0

我会重申pbell说,提供的用于取景的工作代码,因为我不知道您的特定的应用程序是如何工作的:

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 

的重要组成部分,有我们激活搜索第一,所以键击正在发送到正确的应用程序。

同样重要的,这取决于使用情况下,能够为您的应用可访问特权“系统偏好设置” - >“安全&隐私” - >“隐私” - >“辅助功能”

0

听起来像一个时间问题。 (埃里克发布同样的想法,因为我在写这个!):)

您可以添加延迟:

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