vcirilli
vcirilli

Reputation: 331

Applescript delay issue

I am testing applescripts that I will use later in my OSX app. I'm getting a 6 sec delay after the click button command below. After some research it seems that this is a known issue. What I find interesting is, if i use the commercial app QuicKeys to perform the same button click there is no delay, so I assume they found a work around. Anybody have any ideas?

 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

Upvotes: 4

Views: 2196

Answers (2)

Aviral Bansal
Aviral Bansal

Reputation: 413

Was having the same problem and resolved it by enclosing the click causing delay in the ignoring application responses block. Here is a quick summary:

OLD CODE (Causes 6 sec delay)

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

NEW CODE (No delay)

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

Please check detailed answer in the thread listed below.

Speed up AppleScript UI scripting?

Hope this helps.

Upvotes: 2

drkoss
drkoss

Reputation: 79

It seems click or axpress causes a big delay.

Instead - get position and use a third party shell script to do the clicking. Much Much faster.

using clicclik : https://www.bluem.net/en/mac/cliclick/

put in user library/application support/Click

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

end tell

Upvotes: 1

Related Questions