getting U3 serial number on Mac OS X

Phil Davis revdev at pdslabs.net
Sun Dec 17 20:28:16 EST 2006


Phil Davis wrote:
> Hi List,
> 
> I decided to find a way to get a U3 drive's serial number on Mac (OS X 
> only). Sorry, I don't have a method for Linux but would welcome anyone's 
> contribution in this regard.
> 
> Here's what I came up with:

I did a little more homework and decided to make one small change. The 
system_profiler option (parameter) as originally coded doesn't work as expected 
on my PowerPC Mac running 10.3.9; it has to be entered in an older format to 
work. But more important, a parameter that asks system_profiler for USB-only 
info makes it run between 2x and 7x faster (roughly) depending on the state of 
the USB drive (mounted/unmounted/removed).

So here's the updated function, ready for action on PowerPC or Intel Mac:



function u3SerialNumbers
   # Return the serial numbers of all U3 drives currently known to the OS.

   switch the platform

   case "Win32"
     return $U3_DEVICE_SERIAL
     break

   case "MacOS"
     set the itemDelimiter to "."
     if the systemVersion < 10 then return empty -- system is not OS X

     -- prep
     put 0 into x
     put empty into tSerialNumberList
     put shell("system_profiler SPUSBDataType") into tProfile

     -- get U3 serial numbers
     repeat
       put lineOffset("U3 smart drive:",tProfile) into xStart
       if xStart = 0 then exit repeat -- no U3 drive was found

       put lineOffset("Serial Number:",tProfile,xStart) + xStart into xSerNum
       put last word of line xSerNum of tProfile & cr after tSerialNumberList
       delete line 1 to xSerNum of tProfile
     end repeat

     delete last char of tSerialNumberList
     return tSerialNumberList
     break

   default
     return empty
     break
   end switch
end u3SerialNumbers



Thanks -
Phil Davis



More information about the Use-livecode mailing list