Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

pudge (1)

pudge
  (email not shown publicly)
http://pudge.net/
AOL IM: Crimethnk (Add Buddy, Send Message)

I run this joint, see?

Journal of pudge (1)

Wednesday November 27, 2002
01:05 AM

Stupid Mac::Carbon Tricks: Volumes

[ #9169 ]

brian d foy has some code to convert Mac OS paths to Mac OS X paths, and vice versa. To do this, he needs to know the startup volume (because on Mac OS X the startup volume is /, while other mounted volumes are normally under /Volumes/$name/, and in Mac OS all volumes are $name:). He was getting it via AppleScript. Blech.

I sent him some code I think others might find interesting and/or useful.

The MacPerl module (which runs in a limited fashion under Mac OS X perl, in Mac::Carbon) has a function called Volumes(), which returns all mounted volumes in list context, and the startup volume in scalar context. The paths returned text representations of FSSpec data structures, which can be converted to native paths (with slashes in Mac OS X, and colons in Mac OS) with MacPerl::MakePath():

$ perl -MMacPerl=all -le 'print join "\n", map { MakePath($_) } Volumes()'
/
/Volumes/Bourque
/Volumes/Bird
/Volumes/Diablo II Play Disc
/Volumes/Diablo II Cinematics

But that is not too helpful for getting the startup volume name under Mac OS X. You can, however, merely strip off everything up to the ":" in the FSSpec to get the volume name:

$ perl -MMacPerl -le 's/^.+://, print for MacPerl::Volumes()'
Orr
Bourque
Bird
Diablo II Play Disc
Diablo II Cinematics

Now Playing: Growing Young - Rich Mullins (The World As Best As I Remember It, Vol. 2)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I definitely want to make some sort of change to Mac::Path::Util to dump the Applescript stuff, but at the moment it works---just slowly---so it is not very high on my TO DO list.

    Now that you have Mac::Carbon available, I need to get my nose in the Carbon docs, what there is of them anyway, and see what I can do without AppleScript. My priority, though, is to figure out the PropertyList manager because Mac::PropertyList needs more help than Mac::Path::Util.

    Of course, you could just join the Sourceforge p
  • If you want to add me to your projects, feel free. I am already on a dozen or so. :-) I'd ask you before making any changes.

    But yeah, I am not pushing you to make the changes, just making suggestions, and I figured other people might find this particular snippet useful. My only concern is that Mac::Carbon is still "development" level, but then again, what isn't?

    As to Mac::PropertyList, my main wish for it is multilevel data structures. When I wrote a script for eyetv [macperl.org] I did an ugly hack to flatten ever