Get scale of current GameObject in a CG surface shader?

How do I get the scale of the GameObject that has a SpriteRenderer attached to it, and that SpriteRenderer has a material that uses my custom shader, in a CG surface shader?

Shaders cannot get an object’s scale. What you can do is: Create a script that reads the transform’s scale and pass it to the shader.

In your shader, create a property that will store the scale, either float or vector.
Create a script that reads the transform’s scale and passes it to the material that contains your shader.

 mat.SetVector("_Scale", new Vector4(transform.localScale.x,
                                     transform.localScale.y, 
                                     transform.localScale.z, 0f));