4

我正在测试稍后将在我的 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
4

2 回答 2

2

遇到了同样的问题,并通过在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

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

加快 AppleScript UI 脚本编写速度?

希望这可以帮助。

于 2016-04-02T08:02:38.540 回答
1

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

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

使用 clicclik: 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

结束告诉

于 2015-11-10T05:11:12.940 回答