[Pythonmac-SIG] AppleEvents in MacPython 2.3?

Mark Day mday at mac.com
Mon Aug 11 17:10:40 EDT 2003


On Monday, August 11, 2003, at 3:15 PM, Bob Ippolito wrote:

> On Monday, Aug 11, 2003, at 17:47 America/New_York, Larry Meyn wrote:
>
>> On a related subject of colon separated AppleScript paths, how does 
>> one get the name of the root disk for generating absolute  OS 9 style 
>> (colon separated) paths?  The abspath function from the macpath 
>> module doesn't work under OS X , because it uses os.getcwd() which 
>> returns a "/" delimited path.  Are some nice functions that someone 
>> has written that can convert between the two path styles under OS X?
>
> import Carbon.File
> print Carbon.File.FSRef('/').FSGetCatalogInfo(0)[1]
> # looks like the full unicode name for the volume.. but maybe OS9 
> colon paths use the FSSpec paths?

Close.  In general, you convert the POSIX-style path to an FSRef (in 
Carbon this would be FSPathMakeRef; in Python you can also use 
Carbon.File.FSRef()).  Then, call FSGetCatalogInfo and get the FSSpec.  
Look inside the FSSpec for the name.  That's the name used by 
traditional Mac OS 9 style paths.  (Note that there is no such thing as 
a Unicode path as far as the Carbon File Manager is concerned).

Here's what you'd use to get just the name:
print Carbon.File.FSRef('/').FSGetCatalogInfo(0)[2].as_tuple()[2]

The first [2] gets the FSSpec output from FSGetCatalogInfo.  The second 
[2] gets the name out of the FSSpec.

-Mark




More information about the Pythonmac-SIG mailing list