on getMean(theFile)
tell application "Adobe Photoshop CS4"
activate
try
open theFile
on error errmsg
error "Open Error: " & errmsg
end try
set docRef to current document
flatten docRef
if bits per channel of docRef is not eight then set bits per channel of docRef to eight
if mode of docRef is not grayscale then change mode of docRef to grayscale
try
set theMean to do javascript "
var re = RegExp( '[123456789]' );
app.activeDocument.activeLayer.applyAverage();
var arithMean = re.exec(app.activeDocument.channels[0].histogram.toString()).index/2;
return arithMean;
" -- document must be flat, 8-bit, and grayscale
on error
set theMean to false
end try
close docRef saving no
end tell
return theMean
end getMean
I get this error: “illegal return outside of function body”.
In JavaScript you can ONLY return from within the body of a defined function. Or so I think.
on getMean(theFile)
tell application "Adobe Photoshop CS2"
activate
try
open theFile
on error errmsg
error "Open Error: " & errmsg
end try
set docRef to current document
flatten docRef
if bits per channel of docRef is not eight then set bits per channel of docRef to eight
if mode of docRef is not grayscale then change mode of docRef to grayscale
try
set theMean to do javascript "
function getMean() {
var re = RegExp( '[123456789]' );
app.activeDocument.activeLayer.applyAverage();
var arithMean = re.exec(app.activeDocument.channels[0].histogram.toString()).index/2;
return arithMean;} getMean();
" -- document must be flat, 8-bit, and grayscale
on error
set theMean to false
end try
close docRef saving no
end tell
return theMean
end getMean