[Pythonmac-SIG] Creator, type and other means of file detection
Henning Hraban Ramm
hraban at fiee.net
Mon Dec 1 19:34:37 CET 2008
Am 2008-11-30 um 14:29 schrieb Karsten Wolf:
>> If I use MacOS.GetCreatorAndType(filename) on my Intel machine, I
>> get for an EPS:
>> ('09HF', 'FSPE')
>
> Have you checked that with the tool GetFileInfo? I get those
> reversed types/creators for some files on my PPC machine.
I get the reversed types/creators for *all* files (if they got them at
all) with MacOS.GetCreatorAndType.
Thanks for the GFI hint - that tool gets it right:
hraban$ GetFileInfo MontageA3.pdf
file: "MontageA3.pdf"
type: "PDF "
creator: "CARO"
attributes: avbstclinmedz
created: 10/25/2006 15:07:28
modified: 10/25/2006 15:07:28
> Seems like some Apps write bogus type/creator fields.
Don't know. Most modern apps don't use type/creator any more at all.
>> That should read ('FH09', 'EPSF').
>> I didn't knew endian-ness affects the order of strings.
>> Very funny! ;-)
>
> It isn't technically a string. More like UInt32. IIRC type/creator
> are stored in big-endian order.
Ok, but how can I convert those Ints to string?
I get them as Ints also from UTGetOSTypeFromString:
>>> from LaunchServices import UTGetOSTypeFromString
>>> UTGetOSTypeFromString('public.jpeg')
1886741100
>> Anyway, the traditional MacOS type and creator would be a nice
>> addition. The MacOS module is deprecated. I could ask the Finder
>> via appscript, but I wonder if there's a more direct way - I'm
>> surprised the mactypes module's Alias and File classes don't know
>> type and creator.
>
> There are 2 ways I currently know of:
>
> - via LaunchServices
> def get_mac_fileinfo(POSIXPathToFile):
> import LaunchServices as LS
> return LS.GetInfoForPath( POSIXPathToFile, LS.kLSRequestAllInfo)
AttributeError: 'module' object has no attribute 'GetInfoForPath'
Where did you find that function?
I didn't find it in Apple's whole library.
> - via a FSSpec which is deprecated since OS 10.4:
>
> def get_mac_fileinfo(POSIXPathToFile):
> import Carbon.File as CF
> finfo = CF.FSSpec( POSIXPathToFile ).FSpGetFInfo()
> return finfo.Creator, finfo.Type, finfo.Flags, finfo.Fldr,
> finfo.Location
>
> The FSRef of doing things would be via FSGetCatalogInfo.
> Unfortunately the FSGetCatalogInfo structure omits the finderInfo
> field.
That works, but I'd prefer a "future proof" method.
Greetlings from Lake Constance!
Hraban
---
http://www.fiee.net
https://www.cacert.org (I'm an assurer)
More information about the Pythonmac-SIG
mailing list