on run {input, parameters} set counter to 0 set x to 0 beep 1 repeat while counter = 0 and x < 5 tell application "System Settings" activate delay 1 tell application "System Events" tell process "System Settings" click menu item "显示器" of menu "显示" of menu bar item "显示" of menu bar 1 delay 0.5 tell group 1 of group 2 of splitter group 1 of group 1 of window "显示器" try click pop up button 1 delay 0.6 if (menu item "连接键盘和鼠标至" of menu 1 of pop up button 1) exists then click menu item "ipad" of menu 1 of pop up button 1 else click menu item "ipad" of menu 1 of pop up button 1 end if say "连接成功" set counter to 1 on error if x = 0 then say "未找到ipad" set x to x + 1 delay 2 end try end tell end tell end tell end tell end repeat if x = 5 then say "连接中止" end if end run