[Pythonmac-SIG] Python and resource forks under Mac OS X
Lars Damerow
lars-pythonmac@pixar.com
Mon, 18 Nov 2002 10:29:48 -0800
Hello Python-mac folks!
I sent this question to comp.lang.python and got no response, so I'll target a
narrower audience. :)
Do the resource fork manipulation tools in the standard library work under
OS X?
I'm hoping to use them to copy the resource fork out of one file and into
a regular file, and also to copy that file into the resource fork of
another file. I looked at macostools.py, specifically at the copy()
function, and wrote these functions to do the job:
import MacOS
from macostools import BUFSIZ
def joinResources(args):
source, target = args
infile = open(source, "rb")
rf = infile.read(BUFSIZ)
if rf != '':
outfile = MacOS.openrf(target, "wb")
while rf:
outfile.write(rf)
rf = infile.read(BUFSIZ)
outfile.close()
infile.close()
def splitResources(args):
source, target = args
infile = MacOS.openrf(source, "*rb")
rf = infile.read(BUFSIZ)
if rf != '':
outfile = open(target, "wb")
while rf:
outfile.write(rf)
rf = infile.read(BUFSIZ)
outfile.close()
infile.close()
I tried using them to copy the icon from one file to another, but the
Finder doesn't seem to notice the new resource fork; the target file's
icon doesn't change. When I open the target file in a program like
Resourcer, though, it looks like the resource fork was copied correctly.
Baffling!
I also tried using the macostools.copy() to copy a file that had an icon,
and the resulting file was icon-less. :)
Am I doing something wrong? Any tips would be greatly appreciated!
Thanks,
lars
___________________________________________________________
lars damerow
button pusher
lars-pythonmac@pixar.com
"During the brief interview I was asked why I wanted to work for UPS and I
answered that I wanted to work for UPS because I like the brown uniforms.
What did they expect me to say?" -David Sedaris