Connecting AirPlay displays with a keystroke
If you first brought finder to the front in the script, would it work:
   on run {input, parameters}
    tell application &quot;Finder&quot; to activate
    tell application &quot;System Events&quot;
        tell process &quot;SystemUIServer&quot;
            click (menu bar item 1 of menu bar 1 whose description contains &quot;Displays Menu&quot;)
            key code 125
            key code 125
            keystroke return
            delay 5
        end tell
    end tell
    return input
end run