JXA获取文件的大小&校验?

时间:2015-02-28 02:27:34

标签: javascript macos automation itunesconnect jxa

我在Mac上使用JXA(javascript for automation)来尝试自动化iTunes Connect截图上传。因此,我想自动抓取每个图像并上传它,但是对于iTu​​nes Connect允许这个(使用iTMSTransporter),我需要编辑一个XML文件并以位为单位添加每个图像的大小,以及获取校验和(类型= “MD5”)。

我知道我可以手动执行此操作,但我希望自动执行此操作,因为从长远来看,这将为我节省大量时间,每次本地化都有大量不同的屏幕截图。

我已经使用JXA来抓取图像,并获得它们的尺寸,但无法弄清楚尺寸和尺寸。校验和。也许有人可以帮忙?或者如果没有使用JXA,也许有一些JXA可以运行的其他脚本(就像一个shell脚本,我现在没有经验),或者可能是一些脚本我可以提前运行手动将XML导出到文件。从那里我可以使用JXA来解析该文件。

以下是我到目前为止获取图像文件所需的内容:

desktopPath = finder.desktop.url();
desktopPath = desktopPath.substring(7, desktopPath.length);
var imagePath = Application('System Events').folders.byName(desktopPath + '/myImage.png');

imageEvents = Application("Image Events");
imageEvents.launch();
imageEvents.name();

img = imageEvents.open(Path(imagePath));
// now I don't know what to do with the image as the documentation is quite difficult for me to understand

1 个答案:

答案 0 :(得分:0)

我明白了。我不得不使用shell脚本来访问此信息。如果有另一种方式,请点击,但这种方式有效...

// to get the size (newString is the path (as a string) to the file I am getting the size for
var theSize = app.doShellScript("stat -f%z " + newString.replace(" ", "\\ "));

// to get the MD5 checksum (newString is again the path (as a string) to the file I am getting the checksum for
var md5String = newString;
md5String = md5String.replace(" ", "\\ ");
var checksum = app.doShellScript("md5 " + md5String);
checksum = checksum.replace(/\/$/, "").split(' ').pop();
// I popped because I had to format the returned string so it's just the MD5 and not the file path as well. Maybe there is an easier way in shell script, but I'm a newbie to shell scripting