Try :
set USB_Drives to {}
set USB to paragraphs of (do shell script "system_profiler SPUSBDataType -detailLevel basic")
set i to 0
set iMax to count USB
repeat
set i to i + 1
if i > iMax then exit repeat
--if item i of USB contains "Removable Media: Yes" then
if item i of USB contains "Product ID:" then
set {maybe, i} to process_usb_device(i, USB)
if class of maybe is list then set end of USB_Drives to maybe
end if
end repeat
USB_Drives
on process_usb_device(i, USB)
set current_item to item i of USB
set serial_num to "?" # default value
set mount_point to "?" # default value
set isRemovable to false
repeat --until current_item = ""
set i to i + 1
if i > (count USB) then exit repeat
set current_item to item i of USB
log current_item
if current_item contains "Serial Number:" then
set serial_num to text ((offset of ": " in current_item) + 2) through -1 of current_item
else if current_item contains "Removable Media: Yes" then
set isRemovable to true
else if current_item contains "Mount Point:" then
set mount_point to text ((offset of ": " in current_item) + 2) through -1 of current_item
exit repeat
end if
end repeat
if isRemovable then
return {{serial_num, mount_point}, i}
else
return {false, i}
end if
end process_usb_device
One of the problems was that as designed, the original code failed to define the variables serial_num or mount_point.
In my case,it’s serial_num which wasn’t defined.
Here is a part of the contents of the variable USB:
[format]
Patriot Memory:
Product ID: 0x3100
Vendor ID: 0x13fe (Phison Electronics Corp.)
Version: 1.10
Serial Number: 07981808B2F1361F
Speed: Up to 480 Mb/sec
Manufacturer:
Location ID: 0xfa130000 / 5
Current Available (mA): 500
Current Required (mA): 300
Extra Operating Current (mA): 0
Media:
Patriot Memory:
Capacity: 8,01 GB (8 011 120 640 bytes)
Removable Media: Yes
BSD Name: disk2
Logical Unit: 0
Partition Map Type: GPT (GUID Partition Table)
USB Interface: 0
Volumes:
EFI:
Capacity: 209,7 MB (209 715 200 bytes)
BSD Name: disk2s1
Content: EFI
Volume UUID: 0E239BC6-F960-3107-89CF-1C97F78BB46B
Yosemite Install Disk - 10.10.4:
Capacity: 7,67 GB (7 667 146 752 bytes)
Available: 582,6 MB (582 569 984 bytes)
Writable: Yes
File System: HFS+
BSD Name: disk2s2
Mount Point: /Volumes/Yosemite Install Disk - 10.10.4
Content: Apple_HFS
Volume UUID: 72B11AB5-2D53-3564-A5CF-683019424F49
[/format]
As you may see, the first occurrence of the string “Removable Media: Yes” is 11 lines after the one containing the device’s Serial Number so the handler was unable to see it.
Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) dimanche 18 décembre 2016 13:29:24