AppleScript图像事件无法获得类ASDB



想要了解有关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和SIPS进行此操作,但是我想了解有关图像事件的更多信息。我做错了什么可以扔错误?如果有助于我的操作系统是最新的,并且运行Yosemite版本10.10.5。

您需要指定新文件的完整(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

最新更新