Advertisement
bocciaman

Disconnect Bluetooth

Jan 25th, 2021
4,631
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. set DeviceName to "Your Device"
  2.  
  3. tell application "System Events" to tell process "SystemUIServer"
  4.     set bt to (first menu bar item whose description is "bluetooth") of menu bar 1
  5.     click bt
  6.     if exists menu item DeviceName of menu of bt then
  7.         tell (first menu item whose title is DeviceName) of menu of bt
  8.             click
  9.             tell menu 1
  10.                 if exists menu item "Disconnect" then
  11.                     click menu item "Disconnect"
  12.                     return "Disconnecting..."
  13.                 else
  14.                     key code 53 -- hit Escape to close BT menu
  15.                     return "No disconnect button; is it already disconnected?"
  16.                 end if
  17.             end tell
  18.         end tell
  19.     else
  20.         key code 53 -- hit Escape to close BT menu
  21.         return "Cannot find that device, check the name"
  22.     end if
  23. end tell
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement