Created
July 31, 2013 17:21
-
-
Save jamesstout/6124095 to your computer and use it in GitHub Desktop.
Determine Bluetooth Device Status on OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on run | |
-- determine if we are looking for the mouse or the trackpad | |
set doWhat to system attribute "KMVAR_checkWhichDevice" -- set in Keyboard Maestro as M or TP | |
-- create a temp file | |
set theFile to (path to temporary items as string) & "test1.plist" | |
-- system_profiler - reports system hardware and software configuration. | |
-- try it out in a terminal | |
-- system_profiler -listDataTypes | grep -i blue | |
-- SPBluetoothDataType | |
-- write the output to an XML plist file | |
do shell script "system_profiler -xml -detailLevel basic SPBluetoothDataType > " & POSIX path of theFile | |
-- read property list comes from Property List Tools.osax | |
-- from http://www.latenightsw.com/freeware/PListTools/index.html | |
set _plist to read property list file (theFile) | |
set _devices to device_title of item 1 of _items of item 1 of _plist | |
-- |apple wireless trackpad| and |james mouse| are variable names, well, record keys | |
-- Alas AppleScript record keys cannot be read programmatically | |
-- debug and look in _devices for YOUR variable names | |
-- substitute the vars below | |
-- if you have more than 2 devices, add extra try/on error conditions | |
set dev1 to "" | |
set dev1Connected to true | |
if doWhat = "TP" then | |
try | |
set dev1 to |apple wireless trackpad| of item 1 of _devices | |
if device_isconnected of dev1 = "attrib_No" then | |
set dev1Connected to false | |
end if | |
on error | |
set dev1 to |apple wireless trackpad| of item 2 of _devices | |
if device_isconnected of dev1 = "attrib_No" then | |
set dev1Connected to false | |
end if | |
end try | |
end if | |
if doWhat = "M" then | |
try | |
set dev1 to |james mouse| of item 2 of _devices | |
if device_isconnected of dev1 = "attrib_No" then | |
set dev1Connected to false | |
end if | |
on error | |
set dev1 to |james mouse| of item 1 of _devices | |
if device_isconnected of dev1 = "attrib_No" then | |
set dev1Connected to false | |
end if | |
end try | |
end if | |
return dev1Connected | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment