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)
Pudge Patch #8675309
brian_d_foy on 2002-11-27T19:36:47
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 project where I have this set up and make the changes yourself (since you keep changing all of my Mac modules and all I do is type your changes
:)
Either way, thanks for the fix.
SF.net
pudge on 2002-11-27T20:01:47
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 I did an ugly hack to flatten everything before passing it to Mac::PropertyList for parsing.