AppleScriptでBluetoothデバイスへの接続を自動化する
Apple ScriptでBluetoothデバイスへの接続を自動化する方法について。
そもそものきっかけは何かというと
Magic Trackpadを複数のMacで使いたい
キーボードはKeychron K1というのを使っており、複数デバイスでの切り替えは容易
キーボードだけを使って、Magic Trackpadへ接続することをしたい
Apple Scriptで書いて、Spotlightで呼び出せば良さそう
mac - Applescript to connect to bluetooth device - Super User
code:script
activate application "SystemUIServer"
tell application "System Events"
tell process "SystemUIServer"
-- Working CONNECT Script. Goes through the following:
-- Clicks on Bluetooth Menu (OSX Top Menu Bar)
-- => Clicks on device Item
-- => Clicks on Connect Item
set btMenu to (menu bar item 1 of menu bar 1 whose description contains "bluetooth")
tell btMenu
click
tell (menu item "Kaido's Magic Trackpad" of menu 1)
click
if exists menu item "Connect" of menu 1 then
click menu item "Connect" of menu 1
return "Connecting..."
else
key code 53 -- Close main BT drop down if Connect wasn't present
return "Connect menu was not found, are you already connected?"
end if
end tell
end tell
end tell
end tell
"Kaido's Magic Trackpad"の部分を書き換えれば良い
試してみたら大成功。やったね
何が成功したかというと、トラックパッドの接続を解除したあと、このスクリプトで再度接続できるかどうか
ところがMagic Trackpadは複数台のマシンとペアリングできないことが分かった...
なのでこの方法は全くの役立たずに...