【问题标题】:JXA get file's Size & checksum?JXA 获取文件的大小和校验和?
【发布时间】:2015-04-30 21:28:16
【问题描述】:

我在我的 Mac 上使用 JXA(用于自动化的 JavaScript)来尝试自动上传 iTunes Connect 屏幕截图。正因为如此,我想自动抓取每个图像并上传它,但是为了让 iTunes Connect 允许这样做(使用 iTMSTransporter),我需要编辑一个 XML 文件并添加每个图像的大小(以位为单位),并获取校验和( type="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

【问题讨论】:

    标签: javascript macos automation app-store-connect javascript-automation


    【解决方案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
    

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-23
      • 1970-01-01
      • 1970-01-01
      • 2010-09-23
      相关资源
      最近更新 更多