Unable to run a certain AppleScript in BTT, but it seems to run fine in the macOS Script Editor.
It does use IOBluetooth, so i'm wondering if that's the problem.
To test the script, assign the exact name of a bluetooth device to BTT variable "AirPodsWg_DevceName"
Here's a test preset:
AquaTouch AirPods Test v2.bttpreset (237.5 KB)
Here's the script:
use framework "IOBluetooth"
use scripting additions
set widgetVariable to "AirPodsWg_DevceName"
set resetAction to "Reset AirPods Widget"
tell application "BetterTouchTool"
try
set LclAirPodsName to get_string_variable widgetVariable
end try
if LclAirPodsName is missing value or LclAirPodsName is "" then
tell application "BetterTouchTool" to trigger_named resetAction
else
return my connectAirPods(LclAirPodsName, widgetVariable)
end if
end tell
on connectAirPods(LclAirPodsName, widgetVariable) --Connect AirPods Function
tell application "BetterTouchTool"
try
set LclAirPodsName to get_string_variable widgetVariable
end try
end tell
try
-- Get Device
repeat with dev in (current application's IOBluetoothDevice's pairedDevices() as list)
if (dev's nameOrAddress as string) contains LclAirPodsName then set device to dev
end repeat
-- Toggle Device Connection
if not (device's isConnected as boolean) then
device's openConnection()
return (device's nameOrAddress as string) & "
Connecting..."
else
device's closeConnection()
return (device's nameOrAddress as string) & "
Disonnecting..."
end if
on error
----------------- error "connection" alert window ---------------
tell application "BetterTouchTool" to display dialog "Bluetooth Widget could not find your device \"" & LclAirPodsName & "\".
- Make sure it is paired, then try again
- Reset widget and check device name" with title "Bluetooth Widget" with icon note buttons {"Reset Widget", "OK"} default button "OK"
----------------- error "connection" alert window ---------------
if the button returned of the result is "Reset Widget" then
tell application "BetterTouchTool" to trigger_named resetAction
else --if window pressed OK
return
end if
end try
return
end connectAirPods