【问题标题】:Applescript delay issueApplescript 延迟问题
【发布时间】:2016-04-02 16:02:38
【问题描述】:

我正在测试稍后将在我的 OSX 应用程序中使用的 applescript。 在下面的单击按钮命令后,我得到了 6 秒的延迟。 经过一些研究,这似乎是一个已知问题。 我觉得有趣的是,如果我使用商业应用程序 QuicKeys 来执行相同的操作 按钮点击没有延迟,所以我认为他们找到了解决方法。 有人有什么想法吗?

 tell application "System Events"
     tell process "Pro Tools"
         set frontmost to 1
         click button "Track List pop-up" of window 1 
         --  6 seconds delay before next command is sent
         key code 36   -- return key stroke
     end tell
 end tell

【问题讨论】:

  • 我知道这听起来很疯狂,但是如果你在delay 1 命令之后添加delay 1 命令有帮助吗?
  • 不,不是,谢谢你的建议。
  • 这可能不会有什么不同,但是您是否尝试过将click 替换为perform action "AXPress" of?是否有用于显示该窗口的菜单栏项?
  • 是的,我做到了,仍然运行延迟。谢谢

标签: applescript


【解决方案1】:

遇到了同样的问题,并通过在ignoring application responses 块中包含导致延迟的点击来解决它。这里有一个简短的总结:

旧代码(导致 6 秒延迟)

tell application "System Events" to tell process "SystemUIServer"
    set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
    click bt
    tell (first menu item whose title is "SBH80") of menu of bt
        click
        tell menu 1
            if exists menu item "Disconnect" then
                click menu item "Disconnect"
            else
                click menu item "Connect"
            end if
        end tell
    end tell
end tell

新代码(无延迟)

tell application "System Events" to tell process "SystemUIServer"

    set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
    ignoring application responses
        click bt
    end ignoring
end tell

do shell script "killall System\\ Events"
delay 0.1
tell application "System Events" to tell process "SystemUIServer"

    tell (first menu item whose title is "SBH80") of menu of bt
        click
        tell menu 1
            if exists menu item "Disconnect" then
                click menu item "Disconnect"
            else
                click menu item "Connect"
            end if
        end tell
    end tell
end tell

请在下面列出的线程中查看详细答案。

Speed up AppleScript UI scripting?

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    似乎 click 或 axpress 会导致很大的延迟。

    相反 - 获取位置并使用第三方 shell 脚本进行点击。快得多。

    使用点击:https://www.bluem.net/en/mac/cliclick/

    放入用户库/应用支持/点击

    set clickCommandPath to ((path to application support from user domain) as string) & "Click:cliclick"
    set clickCommandPosix to POSIX path of clickCommandPath
    
    tell application "System Events"
     tell process "Pro Tools"
         set frontmost to 1
         tell button "Track List pop-up" of window 1 
         set {xPosition, yPosition} to position
            set x to xPosition
            set y to yPosition
        end tell
        do shell script quoted form of clickCommandPosix & " c:" & xPosition & "," & yPosition
         key code 36   -- return key stroke
     end tell
    

    说完

    【讨论】:

      猜你喜欢
      • 2011-01-14
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-09
      相关资源
      最近更新 更多