1

Image Events で写真のサイズを変更する簡単な Applescript があります。写真はすべてサッカー選手なので、「1.jpg」「4.jpg」などの番号で名前が付けられています。私が遭遇する問題は、異なるディレクトリで複数のプレーヤーのバッチを実行すると、スクリプトが同じファイル名を持ち、以前に実行された別のチームの写真で上書きされることです。繰り返しますが、これらの写真はすべて別のディレクトリに配置されています。最終結果は、プレーヤーの再フォーマットされた写真が混乱することを 2、3 回正常に実行した後です。

これが、Image Events を呼び出すスクリプトの内容です。

on open some_items
    repeat with this_item in some_items
        try
            rescale_and_save(this_item)
        end try
    end repeat
end open


to rescale_and_save(this_item)
    tell application "Image Events"
        launch
        set the target_width to 290
        -- open the image file
        set this_image to open this_item

        set typ to this_image's file type

        copy dimensions of this_image to {current_width, current_height}
        if current_width is greater than current_height then
            scale this_image to size target_width
        else
            -- figure out new height
            -- y2 = (y1 * x2) / x1
            set the new_height to (current_height * target_width) / current_width
            scale this_image to size new_height
        end if

        tell application "Finder" to set new_item to ¬
            (container of this_item as string) & "" & (name of this_item)
        save this_image in new_item as typ

    end tell
end rescale_and_save
4

1 に答える 1

2

同じ名前の複数のアイテムを処理する Image Events でバグを引き起こしたようです。あなたが説明した正確な動作は見られませんが、同様の動作が見られます。

各フォルダを処理した後、単純に Image Events を終了するように指示することをお勧めします。そうすれば混乱しません。( も必要ありませんlaunch。使用する唯一の理由launchは、無題のドキュメント ウィンドウを表示せずに非バックグラウンド アプリケーションを開きたい場合です。)

ちなみに、縮小版で既存の画像を上書きしたい場合は、save this_image. ドキュメントを開いて変更し、保存する場合、Image Events は他のアプリケーションと同じように動作します。

于 2011-08-25T16:09:22.437 に答える