Stupid Mac::Carbon Tricks: Volumes

| | Comments (0)
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
/V olumes/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)

use.perl.org

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on November 26, 2002 10:05 PM.

DIE DIABLO DIE was the previous entry in this site.

Moz 1.2 Upgrade is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.