Applying segment components in python

Please let me know if there is a way to use a script to set the segment component to apply to the selected segment, instead of right clicking.
I would like to create a script and use a shortcut if possible.

node = Layer.selection[0]
newSeg = GSHint()
newSeg.type = 19 #SEGMENT
newSeg.originNode = node
newSeg.name = "_segment.segmentName"
Layer.hints.append(newSeg)

(the definition of SEGMENT was missing, so you have to use the numerical value, for now)

It worked so well.
Thank you!