Stupid Mac::Carbon Tricks: Volumes
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():
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()'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:
/
/Volumes/Bourque
/Volumes/Bird
/V olumes/Diablo II Play Disc
/Volumes/Diablo II Cinematics
$ 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)
Leave a comment