How can I 'Generate Alpha from Grayscale' at runtime from script

Hi, I’m having trouble figuring out how to get this to work. I want to be able import a new texture and have it generate alpha from grayscale just like it would if it had the box checked in the import settings, except this would be an image uploaded to the program by the user and not included in the build… sooo, i can’t use the import settings… I know there must be a simple way to do this…

Here’s the code I’ve got so far:

var shader : Shader;
private var message = "";
private var alpha = 1.0;
private var pathChar = "/"[0];
var pixels : Color[];
var pixel : Color;
var url = "";

function LoadTex (pathToFile : String) {

		var fileIndex = pathToFile.LastIndexOf(pathChar);
		message = "You selected file: " + pathToFile.Substring(fileIndex+1, pathToFile.Length-fileIndex-1);
		
		url = ("file:" + pathToFile);
		
		renderer.material = new Material (shader);
		var texture = Texture2D;
        var www : WWW = new WWW (url);
        yield www;
        renderer.material.mainTexture = www.texture; 
        www.LoadImageIntoTexture(texture);

        var pixels : Color[] = texture.GetPixels();
            				
		      			for (var i : int = 0; i<pixels.Length; ++i) { 
				
				pixel = pixels*;* 
  •  		pixel.a = (pixel.r + pixel.g + pixel.b) / 3.0f;* 
    
  •  		texture.SetPixels(pixels);*
    
  •  		}*
    
  •  texture.Apply();*
    

}

This is the code I’m using to generate a specular-alpha channel from a classical non-alpha specular map.

 var pixels = KsTexture.GetPixels();
 for (var i=0 ; i < pixels.Length; i++) {
    var pixel = pixels*;*

float grey = (float)(((double)pixel.r + (double)pixel.g + (double)pixel.b) / 3.0);
pixels*.a = grey;*
}
KsTexture.SetPixels(pixels);
KsTexture.Apply(updateMipmaps:true);