[Pythonmac-SIG] Get Info Comments

Dante dante@oz.net
Thu, 3 Aug 2000 23:22:20 -0700


Answering my own question after a little help from AECaptureParser 
(thanks Erik!) These two functions will set and get comments with a 
path to a file. They're not tested much, but they've worked well so 
far.

Michael

import aetools, aetypes

def getComment(path):
	"""Get the comment in the Get Info window of a file"""
	AEobject_00 = 
aetypes.ObjectSpecifier(want=aetypes.Type('file'), form="name", 
seld=path, fr=None)
	AEobject_01 = 
aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form="prop", 
seld=aetypes.Type('iwnd'), fr=AEobject_00)
	AEobject_02 = 
aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form="prop", 
seld=aetypes.Type('comt'), fr=AEobject_01)
	_arguments = {'----':AEobject_02}
	_reply, _arguments, _attributes = 
aetools.TalkTo("MACS").send("core", "getd", _arguments, {})
	if _arguments.has_key('errn'):
		raise aetools.Error, aetools.decodeerror(_arguments)
	if _arguments.has_key('----'):
		return _arguments['----']
def setComment(path, comment):
	"Set the comment in the Get Info window of a file"""
	_arguments = {}
	AEobject_00 = 
aetypes.ObjectSpecifier(want=aetypes.Type('file'), form="name", 
seld=path, fr=None)
	AEobject_01 = 
aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form="prop", 
seld=aetypes.Type('iwnd'), fr=AEobject_00)
	AEobject_02 = 
aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form="prop", 
seld=aetypes.Type('comt'), fr=AEobject_01)
	_arguments = {'----':AEobject_02, 'data':comment}
	_reply, _arguments, _attributes = 
aetools.TalkTo("MACS").send("core", "setd", _arguments, {})
	if _arguments.has_key('errn'):
		raise aetools.Error, aetools.decodeerror(_arguments)
	if _arguments.has_key('----'):
		return _arguments['----']
-- 
bang but a whimper/conduct your own funeral/let the light shine through
...
Michael Esveldt
mailto:dante@oz.net - http://velocity.editthispage.com/
#FightThePower on irc.openprojects.net