This will give you an AppleScript record you can then parse normally:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
set theText to (do shell script "system_profiler -xml SPBluetoothDataType")
set theText to current application's NSString's stringWithString:theText
set theData to theText's dataUsingEncoding:(current application's NSUTF8StringEncoding)
-- convert to Cocoa object
set {theThing, theError} to current application's NSPropertyListSerialization's propertyListWithData:theData options:0 |format|:(missing value) |error|:(reference)
if theThing is missing value then error (theError's localizedDescription() as text) number -10000
-- we don't know the class of theThing for coercion, so...
set listOfThing to current application's NSArray's arrayWithObject:theThing
set theRecord to item 1 of (theThing as list)
Also, if all you want is the name of Bluetooth devices, there’s no need to go to all that effort:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "IOBluetooth"
use scripting additions
set allNames to ((current application's IOBluetoothDevice's recentDevices:0)'s valueForKey:"nameOrAddress") as list
set pairedNames to ((current application's IOBluetoothDevice's pairedDevices())'s valueForKey:"nameOrAddress") as list
Wow, splendid, Shane!
So far so good, thereafter i tried to complete my script by adding :
tell application "Finder" to set sel to item 1 of (get selection) as text
#set sel to quoted form of POSIX path of sel
#do shell script "open -a 'Bluetooth File Exchange' " & sel
tell application "Bluetooth File Exchange"
send file sel to device "Redmi"
end tell
If i use the simple shell script i can submit, but have to choose my device, the applescript support for “Bluetooth file exchange” seems broken… (At least on 10.10.5 )
Bluetooth File Exchange’s dictionary says says “send file list of file”. That suggests something more like:
tell application "Finder" to set sel to item 1 of (get selection) as «class furl»
tell application "Bluetooth File Exchange"
send file {sel} to device "Redmi"
end tell
Interesting. It says the same thing in Script Editor here too (v5.0.5) now that I check, but is says list of file in Script Debugger. So I had a look in the sdef, and it says:
<parameter name="file" code="btFs" type="file" optional="yes" list="yes" description="The file to send.">
So I’m not sure why SE is not indicating a list. Not that the sdef proves anything in terms of actual behavior.
I checked the rules for sdef. The list attribute only applies to type elements – parameters don’t have a list attribute. So technically the sdef entry makes no sense.
Script Debugger is assuming that the existence of the list attribute means the author intends the parameter to be a list. Who knows the reality.
I confirm. Tried out lists or single items using hfs or posix path, nothing worked. The script dict of “Bluetooth File Exchange” is a fake.
At this point, i prefer to ignore applescript and use shell instead
do shell script "open -a 'Bluetooth File Exchange' "& sel
…whereas sel has to be a list or single item in quoted posix path format…