I've been fiddling with trying to get this to work for a while, but I just can't seem to wrap my head around it. It's easy to horizontally align text layers via scripting because you can just use ParagraphJustification.CENTER_JUSTIFY, but there isn't a similar control to do the same thing for the y-axis. Essentially I'm trying to figure out how to use this button via my script.
I can grab the layers values for top, height, composition height, and was able to correctly use the examples from this old thread to make it align to the top of the comp, or the bottom of the comp, but haven't been able to wrap my head around coming up with the equation to make it align to the middle of the comp. Any help is greatly appreciated!
Since you're trying to align the middle of the text block to the middle of the the comp instead of the bottom of the text block to the bottom of the comp, you have to divide both heights by two.
I've modified Dan's code accordingly:
var myComp = app.project.activeItem;
var myLayer = myComp.selectedLayers;
var myRect = myLayer.sourceRectAtTime(0,false);
var myPos = myLayer.property("Position").value;
var myY = myPos + myRect.top + myRect.height/2;
var deltaY = myComp.height/2 - myY;
myLayer.property("Position").setValue(myPos + [0,deltaY]);