Apple Script to disconnect wireless keyboard in menu bar on the top of the screen
I'm trying to try disconnecting my wireless keyboard using Applescript.
I came up with this script with UI browser:
activate application "SystemUIServer"
tell application "System Events"
tell application process "SystemUIServer"
click menu item "Disconnect" of menu 1 of menu item "Apple Wireless Key开发者_运维百科board of menu 1 of menu bar item 2 of menu bar 1
end tell
end tell
However, I get getting the following error:
"System Events got an error: Can’t get menu 1 of menu bar item 2 of menu bar 1 of application process "SystemUIServer". Invalid index."
What did I do wrong here, and how can I fix it?
This should work for you. Make sure that it selects the correct menu bar item
tell application "System Events"
tell application process "SystemUIServer"
tell menu bar item 2 of menu bar 1
click
tell menu item "Apple Wireless Mouse" of front menu
click
tell first menu item of front menu
click
end tell
end tell
end tell
end tell
end tell
加载中,请稍侯......
精彩评论