I started toying with the templates to create custom tokens, in particular to be able to have the art go over the name bar. Of course, this isn't really practical when the art doesn't have a transparent background, so when it is the case i add the name bar background directly into the art. However, I would prefer if the actual name text was added on mse (for font purposes and uniformity). I also want the name bar to be under the art when it has transparent background.
My problem is that it is not possible to have a template that allows for both options, because the z index field isn't scriptable. There are workarounds, but they are not pretty, such as creating two templates with two lines of differences, or having two name text fields, and toggling the visible one.
In this case, I edited the image in gimp to remove the area in the background that was over the name bar, and I'm using an altered version of the M15 clear token template where the name bar is split from the card frame, to be able to give it a lower z index than the bottom box. So finally I don't need to be able to script the z index, but it would be nice if it was possible.
If you just want as straight answer, there is no way to directly script the z index. Z index only allows a number value and nothing else. (Trust me, I've tried.) If you want to be able switch between different z indexes, you'll have to make multiple instances of the "same" field, and give them different z index. Then swich wich one is visible using a script. But as cajun kinda pointed out, why would you need to script the z index anyways?