Finding the name of a USB volume

tsj tsj at unimelb.edu.au
Wed Jan 6 16:48:51 EST 2010


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 relevant applescript snippets are...

tell application "System Events" to get the local volume of disk
[volumepath]

tell application "System Events" to get the ejectable of disk [volumepath]

Would that do it?

Terry...


On 7/01/10 2:36 AM, "Richard Gaskin" <ambassador at fourthworld.com> wrote:

> I'm making a custom installer in which I want to provide the option of a
> normal desktop install to the hard drive and a zero-footprint install to
> a removable USB drive (no registry entries, prefs stored in the app
> folder, etc.).
> 
> To help make this simple for the user I'd like to present a list of
> available USB drives if they choose that option, so they can pick the
> target for the install.
> 
> Phil Davis was kind enough to share some pointers in his libUsbDrive
> library (see <http://pdslabs.net/usb/index.html>), which has me
> exploring the use of shell calls on OS X to system_profiler, e.g.:
> 
>     get shell("system_profiler -xml SPUSBDataType")
> 
> While the info returned there contains a lot of very useful stuff, the
> one thing I'm not able to find is the name of the volume as it appears
> to the user on the desktop.
> 
> Well, sometimes, that is.
> 
> It seems that if I've named the drive in the Finder, the Volumes section
> of the data returned from that shell call is filled in, and includes the
> apparent name of the volume.
> 
> But drives which haven't been given a name on a Mac system appear on the
> desktop as "Untitled", and although the data from the system_profiler
> shows it as a removable drive there is no Volumes section included and
> hence no way to know the name of the drive as it appears to the user.
> 
> When there is is a Volumes section the _name key there shows the name as
> it appears in the Finder, but drives that have not explicitly been given
> a name appear as "Untitled" or "Untitled 1", etc., in the Finder and the
> corresponding _name key from system_profiler is something different (for
> example my card reader device has a _name value of "Generic USB2.0 card
> " in system_profiler, but on the desktop it appears as "Untitled 1").
> 
> Do any of you know a way I can use shell or AppleScript to obtain the
> apparent name of a removable drive when system_profiler fails to return it?
> 
> Extra bonus points:  what shell calls would I use to get this info on
> Linux?  I think I have the Windows side of things down, but I'll need to
> work out the Linux side soon.
> 
> TIA -
> 
> --
>   Richard Gaskin
>   Fourth World
>   Rev training and consulting: http://www.fourthworld.com
>   Webzine for Rev developers: http://www.revjournal.com
>   revJournal blog: http://revjournal.com/blog.irv
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-revolution
> 




More information about the use-livecode mailing list