RGB画像以外にはFinderラベルをつける
【Safari・FireFox用Script Editorで開く】 |
| ソース | |
|---|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 | Finder ラベル番号 |
| 006 | 1:オレンジ |
| 007 | 2:レッド |
| 008 | 3:イエロー |
| 009 | 4:ブルー |
| 010 | 5:パープル |
| 011 | 6:グリーン |
| 012 | 7:グレー |
| 013 | |
| 014 | カラースペース判定 |
| 015 | CMYK |
| 016 | Eight channel |
| 017 | Eight color |
| 018 | Five channel |
| 019 | Five color |
| 020 | Gray |
| 021 | Lab |
| 022 | Named |
| 023 | RGB |
| 024 | Seven channel |
| 025 | Seven color |
| 026 | Six channel |
| 027 | Six color |
| 028 | XYZ |
| 029 | |
| 030 | |
| 031 | com.cocolog-nifty.quicktimer.icefloe *) |
| 032 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 033 | use AppleScript version "2.8" |
| 034 | use scripting additions |
| 035 | property listAliasFilePath : {} as list |
| 036 | |
| 037 | ######################## |
| 038 | #【設定項目】Finder ラベル番号 |
| 039 | property numIndexNo : 3 as integer |
| 040 | |
| 041 | |
| 042 | ######################## |
| 043 | # RUN |
| 044 | # on run {listAliasFilePath} |
| 045 | |
| 046 | on run |
| 047 | |
| 048 | if (count of listAliasFilePath) = 0 then |
| 049 | ######################## |
| 050 | #ダイアログ |
| 051 | set strMsg to ("画像ファイル 選択") as text |
| 052 | set strPrompt to ("画像ファイル を選択してください" & return & "複数選択可") as text |
| 053 | set aliasDesktopDirPath to (path to desktop from user domain) as alias |
| 054 | set listUTI to {"public.item"} as list |
| 055 | try |
| 056 | tell application "Finder" |
| 057 | tell application "SystemUIServer" |
| 058 | activate |
| 059 | set listAliasFilePath to (choose file strMsg with prompt strPrompt default location aliasDesktopDirPath of type listUTI with invisibles and multiple selections allowed without showing package contents) as list |
| 060 | end tell |
| 061 | end tell |
| 062 | on error strErrMes number numErrNo |
| 063 | log strErrMes & numErrNo |
| 064 | return false |
| 065 | end try |
| 066 | if listAliasFilePath is {} then |
| 067 | return false |
| 068 | end if |
| 069 | end if |
| 070 | ######################## |
| 071 | #OPENへ渡す |
| 072 | set boolDone to (open listAliasFilePath) |
| 073 | set listAliasFilePath to {} as list |
| 074 | try |
| 075 | with timeout of 3 seconds |
| 076 | tell application "System Events" to quit |
| 077 | end timeout |
| 078 | on error strErrMes number numErrNo |
| 079 | log "Quit System Events" & strErrMes & numErrNo |
| 080 | return false |
| 081 | end try |
| 082 | |
| 083 | return boolDone |
| 084 | end run |
| 085 | |
| 086 | ######################## |
| 087 | # OPEN |
| 088 | on open listAliasFilePath |
| 089 | |
| 090 | set listImageUTI to {"public.avif", "org.webmproject.webp", "public.png", "public.tiff", "public.jpeg", "public.heic", "com.adobe.photoshop-image"} as list |
| 091 | |
| 092 | |
| 093 | repeat with itemAliasFilePath in listAliasFilePath |
| 094 | |
| 095 | |
| 096 | set aliasItemFilePath to itemAliasFilePath as alias |
| 097 | set recordInfoFor to (info for aliasItemFilePath) as record |
| 098 | set boolIsDir to (folder of recordInfoFor) as boolean |
| 099 | if boolIsDir is false then |
| 100 | set boolIsAlias to (alias of recordInfoFor) as boolean |
| 101 | if boolIsAlias is false then |
| 102 | set strUTI to (type identifier of recordInfoFor) as text |
| 103 | set boolIsImageFile to (listImageUTI contains strUTI) as boolean |
| 104 | if boolIsImageFile is true then |
| 105 | set strColorSpace to doGetColorSpace(aliasItemFilePath) |
| 106 | |
| 107 | if strColorSpace is "Gray" then |
| 108 | #グレイと白黒 |
| 109 | set boolDone to doSetGrayLabel(aliasItemFilePath) as boolean |
| 110 | else |
| 111 | #RGBではないなら ラベル |
| 112 | if strColorSpace is not "RGB" then |
| 113 | set boolDone to doSetFinderLabel(aliasItemFilePath) as boolean |
| 114 | end if |
| 115 | end if |
| 116 | end if |
| 117 | end if |
| 118 | end if |
| 119 | end repeat |
| 120 | |
| 121 | |
| 122 | set listAliasFilePath to {} as list |
| 123 | return true |
| 124 | end open |
| 125 | ######################## |
| 126 | #カラースペースを調べる |
| 127 | on doGetColorSpace(argAliasFilePath) |
| 128 | |
| 129 | set aliasFilePath to argAliasFilePath as alias |
| 130 | tell application "Finder" |
| 131 | set listAliasFilePath to {aliasFilePath} as alias list |
| 132 | end tell |
| 133 | set refColorSpace to missing value |
| 134 | set strReturnColorSpace to missing value |
| 135 | set refOpenImage to missing value |
| 136 | tell application "Image Events" |
| 137 | launch |
| 138 | try |
| 139 | set refOpenImage to open (first item of listAliasFilePath) |
| 140 | set listResolution to (resolution of refOpenImage) as list |
| 141 | set numResolution to (first item of listResolution) as integer |
| 142 | set strResolution to numResolution as text |
| 143 | set listDimensions to (dimensions of refOpenImage) as list |
| 144 | set numPxW to (first item of listDimensions) as integer |
| 145 | set numPxH to (last item of listDimensions) as integer |
| 146 | set refColorSpace to (color space of refOpenImage) |
| 147 | close refOpenImage |
| 148 | on error strErrMsg number numErrNo |
| 149 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 150 | #エラーした時必ずCLOSEしないと再起動するまでOPENが残るので |
| 151 | #Image EventにはTRY ERRORの処理は必須 |
| 152 | close refOpenImage |
| 153 | set strReturnColorSpace to "" as text |
| 154 | return strReturnColorSpace |
| 155 | end try |
| 156 | #スクリプトアプリケーションにした場合にカラースペース名をテキストに出来ないので |
| 157 | #ここは、イメージイベント内でプロパティのVALUEで分岐させて取り値をテキストにする |
| 158 | if refColorSpace = missing value then |
| 159 | set strReturnColorSpace to "" as text |
| 160 | else if refColorSpace is Gray then |
| 161 | set strReturnColorSpace to "Gray" as text |
| 162 | else if refColorSpace is RGB then |
| 163 | set strReturnColorSpace to "RGB" as text |
| 164 | else if refColorSpace is Lab then |
| 165 | set strReturnColorSpace to "Lab" as text |
| 166 | else if refColorSpace is XYZ then |
| 167 | set strReturnColorSpace to "XYZ" as text |
| 168 | else if refColorSpace is named then |
| 169 | set strReturnColorSpace to "Named" as text |
| 170 | else |
| 171 | set strReturnColorSpace to "Multi-channel" as text |
| 172 | end if |
| 173 | |
| 174 | end tell |
| 175 | |
| 176 | return strReturnColorSpace |
| 177 | |
| 178 | end doGetColorSpace |
| 179 | |
| 180 | |
| 181 | ######################## |
| 182 | #ラベルをつける |
| 183 | on doSetFinderLabel(argAliasFilePath) |
| 184 | set aliasFilePath to argAliasFilePath as alias |
| 185 | try |
| 186 | tell application "Finder" |
| 187 | tell file aliasFilePath |
| 188 | set label index to numIndexNo |
| 189 | end tell |
| 190 | end tell |
| 191 | on error strErrMsg number numErrNo |
| 192 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 193 | return false |
| 194 | end try |
| 195 | return true |
| 196 | |
| 197 | end doSetFinderLabel |
| 198 | |
| 199 | ######################## |
| 200 | #ラベルをつける グレイ 白黒 |
| 201 | on doSetGrayLabel(argAliasFilePath) |
| 202 | set aliasFilePath to argAliasFilePath as alias |
| 203 | try |
| 204 | tell application "Finder" |
| 205 | tell file aliasFilePath |
| 206 | set label index to 7 |
| 207 | end tell |
| 208 | end tell |
| 209 | on error strErrMsg number numErrNo |
| 210 | log "No: " & numErrNo & linefeed & "Error:" & strErrMsg |
| 211 | return false |
| 212 | end try |
| 213 | return true |
| 214 | |
| 215 | end doSetGrayLabel |
| 216 | |
| AppleScriptで生成しました | |
