You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Detect Bluetooth device

Hello,
Is there a way to detect if a bluetooth device is connected and/or disconnected.
I found something here ( http://forums.macrumors.com/showthread.php?t=701524) but it is a little different than what I want.
Basically a script that can find out if a specified bluetooth device is connected. Then if it is, it does something. Then it checks every like 10 seconds or so to see if it is connected. Then if it is disconnected, it does something else.

The only issue I see is after it checks, it will run the same thing over and over. So there needs to be a way for it to check but after the first time it detects if a device is connected, it does not run that part over and over untill the device is marked as disconnected.

I know this is a lot so I can re explain but someone let me know if this is possible.

Mac Book Pro, Mac OS X (10.6.4)

Posted on Sep 8, 2010 1:43 PM

Reply
Question marked as Top-ranking reply

Posted on Sep 8, 2010 3:05 PM

Could you not see if the information is in the results of…

set BT to do shell script "system_profiler SPBluetoothDataType"
17 replies

Sep 11, 2010 7:13 PM in response to filmmakerc14


repeat
set statusOld to checkStatus()
set statusNew to checkStatus()
repeat while statusOld is equal to statusNew
delay 1 --for 1 second checks
set statusNew to checkStatus()
end repeat
if statusNew is true then
display dialog "Device Added - put some real code here"
else
display dialog "Device Removed - put some real code here"
end if
end repeat
on checkStatus()

(*Delete the 2 lines below when done testing*)
set myString to button returned of (display dialog "Connected?" buttons {"Yes", "No"})
set myString to "name: DR-BT101 Connected: " & myString

(*uncomment line below when done testing*)
--set myString to do shell script "system_profiler SPBluetoothDataTyp"

--initial check if it's not even there
if myString does not contain "DR-BT101" then
return false
else

--find out if connected/disconnected
set AppleScript's text item delimiters to "name:"
set myList to the text items of myString --each item of mylist is now one of the devices

set numberOfDevices to count of myList
set counter to 1
repeat numberOfDevices times --loop through each devices checking for Connected string
if item counter of myList contains "DR-BT101" then
if item counter of myList contains "Connected: Yes" then
return true
else if item counter of myList contains "Connected: No" then
return false
else
display dialog "Error Parsing" --this shouldn't happen
end if
end if
set counter to counter + 1
end repeat
end if
end checkStatus

I realized that you want different things to happen whether the device is added or removed. Try running this script in your editor and pay attention to the comments for removing 2 lines and uncommenting another when you are done testing it.

Sep 11, 2010 9:16 PM in response to taylor.henderson

Yes that is what I am looking for.
I believe it also works so that it does not let the script do something if a device is connected, until it is disconnected.
I also believe it would do this for the device if it not connected.

I will have to try this with an actual device soon. I will let you know how it works.

Thanks again for your help!

Detect Bluetooth device

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.