开发者

Apple Script to disconnect wireless keyboard in menu bar on the top of the screen

开发者 https://www.devze.com 2023-04-12 11:06 出处:网络
I\'m trying to try disconnecting my wireless keyboard using Applescript. I came up with this script with UI browser:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消