Finding the name of a USB volume

Phil Davis revdev at pdslabs.net
Fri Jan 8 02:05:07 EST 2010


On 1/7/10 9:36 PM, Scott Morrow wrote:
> Very nice.  Thanks, Phil!
>
> Scott Morrow
>
> Elementary Software
> (Now with 20% less chalk dust!)
> web       http://elementarysoftware.com/
> email     scott at elementarysoftware.com
> ------------------------------------------------------
>    
You're welcome!

Here is an improved version of the original handler. It adds a "Device:" 
label to the device name and replaces the single "Volumes:" label before 
ALL volume descriptions with a "Volume:" label before EACH volume 
description (should make it easier to break out descriptions of each 
partition on a USB drive).

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
       put empty into tNewLine
       repeat for each item tItem in tLine
          put word 1 to -1 of tItem & tab after tNewLine
       end repeat

       -- insert a device tag at beginning of device description
       delete last char of item 1 of tNewLine -- trailing colon
       put "Device: " before item 1 of tNewLine

       -- remove single 'volumes:' tag at beginning of all volume 
descriptions
       replace "Volumes:" & tab with empty in tNewLine

       -- insert a "volume: " tag at the start of each volume description
       replace (colon & tab) with cr in tNewLine -- break after each 
volume name
       repeat with x = 1 to (the number of lines in tNewLine - 1)
          put "Volume: " before last item of line x of tNewLine
       end repeat
       replace cr with tab in tNewLine

       -- append finished line to rest of data
       put cr into last char of tNewLine
       put tNewLine after tNewData
    end repeat
    delete last char of tNewData

    -- return the data
    return tNewData
end macUsbDrives

-- 
Phil Davis

PDS Labs
Professional Software Development
http://pdslabs.net




More information about the use-livecode mailing list