Applescript delay issue

前端 未结 2 1299
花落未央
花落未央 2021-01-06 15:10

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

相关标签:
2条回答
  • 2021-01-06 15:37

    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

    0 讨论(0)
  • 2021-01-06 15:38

    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.

    0 讨论(0)
提交回复
热议问题