2013-04-20 191 views
1

我正在測試稍後將在我的OSX應用程序中使用的applescript。 我在下面的點擊按鈕命令後得到6秒的延遲。 經過一番研究,似乎這是一個已知的問題。 我覺得有趣的是,如果我使用商業應用QuicKeys執行相同的 按鈕點擊沒有延遲,所以我假設他們找到了解決辦法。 有人有什麼想法嗎?Applescript延遲問題

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 
+0

我知道這聽起來很瘋狂,但是如果你在'click button'命令之後添加'delay 1'命令,它會有幫助嗎? – matt 2013-04-21 03:29:58

+0

不,它沒有,謝謝你的建議。 – vcirilli 2013-04-21 20:04:05

+0

它可能不會有所作爲,但是您是否嘗試用'perform action「AXPress」of'替換'click'?如果有用於顯示該窗口的菜單欄項目? – user495470 2013-04-21 23:51:52

回答

0

看來點擊或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 

末告訴

+0

thx的帖子。雖然沒有解決我的延遲問題。 – vcirilli 2016-04-03 03:30:00

2

有同樣的問題,並通過封閉單擊導致延遲解決它ignoring application responses塊。這裏是一個快速摘要:

OLD CODE(原因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?

希望這會有所幫助。