1

Mac のイメージ イベントについて詳しく知りたい ファイルをあるタイプから別のタイプに保存する方法を学ぼうとしています。たとえば、名前の付いた BMP イメージがある場合、foobar.bmpそれを保存する方法を学びたかったのfoobar.jpgですが、ハンドラーでエラーが発生します。

イメージ イベントにエラーが発生しました: イメージ "foobar.bmp" の «クラス asDB» ID (アプリケーション "イメージ イベント") を取得できません。

ハンドラー内の私のコード:

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 を使用してこれを行うこともできますが、Image Events について詳しく知りたいです。エラーをスローするために何が間違っていますか? OS が最新で、Yosemite バージョン 10.10.5 を実行していることが役立つ場合。

4

1 に答える 1

0

alias宛先フォルダーへの指定子ではなく、新しいファイルのフル (HFS または POSIX) パスを指定する必要があります。

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
于 2016-12-28T15:25:28.323 に答える