LoginSignup
10
1

More than 5 years have passed since last update.

猫写真のサイズがポストカードに使えるかどうか判別する AppleScript を書いた

Last updated at Posted at 2017-12-04

概要

弊社猫社員のポストカードを販売するにあたって、サーバに溜め込まれた猫写真の中から、ポストカードに使えるサイズの画像を抽出するようにオーダーされたので、AppleScript で書いてみました。

環境

  • MacOS 10.12.x
  • Adobe Photoshop CC 2017

ポストカードのサイズ

  • 幅 :100mm
  • 高さ:148mm

仕様

  • ドロップレット形式
  • ドラッグ&ドロップされたファイル群を一つずつ開く
  • 幅・高さがポストカードのサイズで定義されたものより大きければ、ファイルにタグをつける(サンプルではレッドのタグ)
  • ファイルは保存せず閉じる

ソースコード

ソースコード
on open fileList
    repeat with i in fileList
        tell application id "com.adobe.photoshop"
            --ルーラーの設定を退避後、mmに変更(サイズをmmで判定するため)
            set oldUnits to ruler units of settings
            set ruler units of settings to mm units
            open i
            tell current document
                activate
                set filePath to POSIX path of (file path as alias)
                --再サンプルのチェックを外した状態で解像度を350に変更(350は一般的な印刷時の解像度)
                resize image resolution 350 resample method none
                --画像が100x148より大きいか判別
                if (width > 100 and height > 148) then
                    my addTagOnFile(filePath)
                else if (width > 148 and height > 100) then
                    my addTagOnFile(filePath)
                end if
                --保存しないで閉じる
                close saving no
            end tell
            --ルーラーの設定を元に戻す
            set ruler units of settings to oldUnits
        end tell
    end repeat
end open

to addTagOnFile(filePath)
    --タグをShell Scriptでつける
    do shell script "xattr -w com.apple.metadata:_kMDItemUserTags '(\"レッド\\n6\")' " & filePath
end addTagOnFile

ポストカードに興味がある方は

ポストカードはもちろん、みるく部長のトートバッグもとってもかわいいので、ぜひ!

まとめ

  • AppleScript はドラッグ&ドロップで実行する形式がとても使いやすくて良い
  • 猫写真の整理は幸せな気持ちになれるのでおすすめ
10
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
1