Finding the name of a USB volume
Phil Davis
revdev at pdslabs.net
Wed Jan 6 21:46:03 EST 2010
Here is an simplified 'system_profiler' output approach. It returns one
tab-delimited line of info per detachable USB storage device, with all
the data items known to system_profiler for each device. NOTE: It
expects system_profiler output to be in English.
function macUsbDrives
-- get USB device info from system profiler
put shell("system_profiler -detailLevel full SPUSBDataType") into tData
-- convert data to one line per USB device
replace (colon & cr & cr) with numToChar(245) in tData -- device name
replace (cr & cr) with numtoChar(250) in tData
replace cr with tab in tData
replace numtoChar(245) with (colon & tab) in tData
replace numtoChar(250) with cr in tData
-- remove records for all but USB drives (English data only)
filter tData with "*Detachable Drive: Yes*"
-- remove space-padding from items in each line
set the itemDel to tab
repeat for each line tLine in tData
repeat for each item tItem in tLine
put word 1 to -1 of tItem & tab after tNewData
end repeat
put cr into last char of tNewData
end repeat
delete last char of tNewData
-- return the data
return tNewData
end macUsbDrives
HTH -
Phil Davis
On 1/6/10 5:50 PM, Phil Davis wrote:
> On 1/6/10 3:31 PM, Richard Gaskin wrote:
>> tsj wrote:
>>> Richard - I haven't got an unnamed USB drive handy to test this with
>>> but
>>> what does the volumes function return when one is mounted? Does this
>>> give
>>> you the expected "untitled" (or "untitled 1" etc)?
>>>
>>> If so, you could iterate through the listed volumes using a couple of
>>> applescripts to determine whether the drive was local (false if it's a
>>> network drive) ejectable (false if it's internal) and then if you
>>> get two
>>> false results you can attempt to open a file on the volume. If that
>>> gives
>>> you an error then the drive is write protected. If it passes all
>>> tests then
>>> you're left (presumably) with an external USB or Firewire drive.
>
> The "passes all tests" list can also includes mounted .dmg files.
>
> Thanks for posting this - very helpful.
--
Phil Davis
PDS Labs
Professional Software Development
http://pdslabs.net
More information about the use-livecode
mailing list