Question
javascript for automation vs applescript - dimensions
Hello,
I wrote two scripts. jxa script works very slowly compared to ap. the scripts are supposed to count the dimensions of selected files with a resolution of 2540. There may be about 30 selected files and then it feels that jxa works several times slower, but I need jxa for windows. How can I speed up this script?
jxa:
var suma = 0;
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var finder = Application("Finder");
var imageEvents = Application("Image Events");
for(var i=0; i<finder.selection().length; i++) {
var path = finder.selection()[i].url();
var newPath = path.substring(7);
var myPath = decodeURI(newPath);
var img = imageEvents.open(myPath);
var w = img.dimensions()[0];
var h = img.dimensions()[1];
var wRes = img.resolution()[0];
var hRes = img.resolution()[1];
var m2 = (w/wRes*0.0254) * (h/hRes*0.0254);
var suma = suma+m2;
};
app.displayDialog(suma.toFixed(3));ap:
tell application "Finder"
set lista to selection
repeat with i from 1 to (count lista)
set {item i of lista} to {item i of lista as string}
end repeat
end tell
set m2 to 0
tell application "Image Events"
repeat with i from 1 to (count lista)
launch
set plik to open (item i of lista)
copy the dimensions of plik to {x, y}
close plik
set suma to ((x * 0.01) / 1000) * ((y * 0.01) / 1000)
set m2 to m2 + suma
end repeat
end tell
display alert m2
thanks for the answers!
