AppleScript切换蓝牙

use*_*304 2 macos applescript bluetooth osx-mavericks

在OS X 10.8中,我有一个整洁的小AppleScript,我用它来快速切换蓝牙而不使用鼠标.

我更新到10.9,它为系统偏好设置添加了几个UI更改.除此之外,它还取代了将蓝牙从复选框切换到按钮的元素.我的脚本现在已经坏了,因此我的工作流程也是如此.

问题是按钮的名称从"打开蓝牙"变为"关闭蓝牙",具体取决于其状态.我没有充分掌握AppleScript来找出解决方法,并且想知道你们是否可以帮助我.

Lri*_*Lri 7

这在10.9中对我有用:

tell application "System Preferences"
    reveal pane "com.apple.preferences.Bluetooth"
end tell
tell application "System Events" to tell process "System Preferences"
    click button 6 of window 1
end tell
quit application "System Preferences"
Run Code Online (Sandbox Code Playgroud)

你也可以使用blueutil:

/usr/local/bin/blueutil|grep -q 'Power: 1';/usr/local/bin/blueutil power $?
Run Code Online (Sandbox Code Playgroud)

  • 使用 blueutil 进行切换的更短方法(我使用的是 2.9.0 版本):`blueutil -ptoggle` (2认同)