【问题标题】:AppleScript Image Events cant get class asDBAppleScript 图像事件无法获取类 asDB
【发布时间】:2016-12-28 14:36:25
【问题描述】:

想要了解有关 Mac 的图像事件的更多信息,我正在尝试学习如何将文件从一种类型保存到另一种类型。例如,如果我有一个名为 foobar.bmp 的 BMP 图像,我想学习如何将其保存为 foobar.jpg,但在我的处理程序中出现错误:

图像事件出错:无法获取 «class asDB» id(应用程序 图像“foobar.bmp”的“图像事件”。

我的处理程序中的代码:

tell application "Finder"
    set directory to (choose folder with prompt "Please select a directory.")
    set someImages to (files of folder directory where name extension is "bmp") as alias list
    repeat with someImage in someImages
        tell application "Image Events"
            launch
            set workingImage to open someImage
            save workingImage as JPEG in directory
            close workingImage
        end tell
    end repeat
end tell

我确实测试了save 是否可能需要 POSIX 路径而不是别名路径:

set directoryPosix to (POSIX path of directory)

并更改了save

save workingImage as JPEG in directoryPosix

但我仍然产生同样的错误,我不明白为什么。该代码有效,但只是引发错误,搜索后我无法找到解决方案。我已经知道如何使用 ImageMagick 使用 Bash 执行此操作,并且可以使用 AppleScript 和 SIP 执行此操作,但我想了解有关图像事件的更多信息。我做错了什么抛出错误?如果它有助于我的操作系统是最新的并运行 Yosemite 版本 10.10.5。

【问题讨论】:

    标签: applescript image-events


    【解决方案1】:

    您需要指定新文件的完整(HFS 或 POSIX)路径,而不是目标文件夹的 alias 说明符:

    set directory to (choose folder with prompt "Please select a directory.") as text
    tell application "Finder" to set someImages to (files of folder directory where name extension is "bmp") as alias list
    
    tell application "Image Events"
        launch
        repeat with someImage in someImages
            set workingImage to open someImage
            set fileName to name of workingImage
            set newFilePath to directory & text 1 thru -4 of fileName & "jpg"
            save workingImage as JPEG in newFilePath
            close workingImage
        end repeat
    end tell
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-18
      • 1970-01-01
      • 2022-01-20
      • 2017-01-29
      • 1970-01-01
      • 2015-10-02
      相关资源
      最近更新 更多