Applescript delay issue

前端 未结 2 1325
花落未央
花落未央 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条回答
  •  猫巷女王i
    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.

提交回复
热议问题