[Tutor] Re: making an alias of a folder

Christopher Smith csmith@blakeschool.org
Mon, 11 Feb 2002 09:09:35 -0600

Danny Yoo writes:
>I don't have a Macintosh available at the moment, so I can't test this,
>but I believe that the macfs.NewAliasMinimalFromFullPath() is the function
>that you're looking for:
>    http://www.python.org/doc/current/mac/module-macfs.html

I looked at that and didn't initially think that it was going to help but
your saying it might be the thing made me look again.  Though I don't know
if I've got everything right, I do have a routine now that will make an
alias of a folder.  I don't understand the "relative" option yet, though. 
Those more in the know about the mac toolbox may see other things that I
don't know as well. :-)  Until the macostools.makealias is fixed, this is
a workaround.

Thanks for the nudge, Danny.  And thanks for filing a bug report, Jack.


import macfs
from Carbon import Res

# Doesn't yet handle the relative option; I'm not sure what this
# means for an alias yet.
def mkfolderalias(src, dst, relative=None):
	"""Create an alias to a folder"""
	alias = macfs.NewAliasMinimalFromFullPath(dst)
	dstfss = alias.Resolve()[0]
	Res.FSpCreateResFile(dstfss, 'MACS', 'fdrp', -1)
	# make it point at the src and update the resource 
	# {see Mac Lib Modules; v 2.2; sect 2.4.2 Alias Objects}
	# If the source is itself an alias, the new alias
	# will point at the same thing that the src alias is
	# pointing at.  If the src is *not* a folder it will then
	# still point at the file but the icon will be a folder
	# icon until it is updated by the Finder (e.g. after 
	# double clicking on it in the Finder).
	h = Res.FSpOpenResFile(dstfss, 3)
	resource = Res.Resource(alias.data)
	resource.AddResource('alis', 0, '')
	# turn it into an alias icon; before doing this the 
	# folder icon will be "busy and in use by the system"
	dstfss = macfs.FSSpec(dst)
	dstfinfo = dstfss.GetFInfo()
	dstfinfo.Flags = dstfinfo.Flags|0x8000    # Alias flag