1

我在我的 Mac 上使用 JXA(用于自动化的 JavaScript)来尝试自动上传 iTunes Connect 屏幕截图。正因为如此,我想自动抓取每个图像并上传它,但为了让 iTunes 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
4

1 回答 1

1

我想到了。我不得不使用 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
于 2015-02-28T19:13:38.893 回答