OS Xの「サービス」を使用して、ファイルの照合。
【使用目的】
InDesignにアタリ画像が配置されていて、本番画像に差し替えなければならない。
だが、本番画像が完全に揃っているとは限らないし、必要のない画像も入っている。
また、ある画像はキリヌキもしなければならない。
アタリ画像はEPS形式だが、本番画像はJPGだったりする。
そんな時に役立つのが、今回の「ファイル照合」です。
ファイル名を照らし合わせて、同じ名前のファイルを見つけてくれます。
【作成方法】
アプリケーション > Automator > サービスを選択。
ライブラリ > AppleScriptを実行をダブルクリック。
画像のように、AppleScriptコードを入力して、
「ファイルの照合」などの適当な名前で保存。
▼AppleScriptコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
on run {input, parameters} set LabelFileList to {} set errorFileList to {} set errorFileList2 to {} set iNameList to {} set cFileList to {} set cFileList2 to {} set Copyclipboard to get the clipboard set clipFileList to paragraphs of Copyclipboard repeat with cFile in clipFileList set cFile to repChar(cFile, return, "") of me set cExt to retExtNameFromFilenameStr(cFile as Unicode text) of me --ファイル名文字列から拡張子のみ取得する if cExt = "" then else try set cExt to cExt as number --本当に拡張子か簡易チェック 例)Vol.1など on error set cFile to retFileNameWithoutExt(cFile as Unicode text) of me --拡張子をトル end try end if if (cFile = "") then else set the end of cFileList2 to cFile end if end repeat repeat with iFile in input set myInfo to (info for iFile) set iName to name of myInfo set iExt to name extension of myInfo set iExt2 to retExtNameFromFilenameStr(iName as Unicode text) of me --ファイル名文字列から拡張子のみ取得する --activate --display dialog ("." & iExt) & "+" & iExt2 if ("." & iExt) = iExt2 then try set iExt to iExt as number --本当に拡張子か簡易チェック 例)Vol.1など on error --set iName to repChar(iName, ("." & iExt), "") of me --拡張子をトル set iName to retFileNameWithoutExt(iName) of me --拡張子をトル end try end if set the end of iNameList to iName if iName is in cFileList2 then set the end of LabelFileList to iFile else set the end of errorFileList to iName & return --未照合リスト end if end repeat repeat with cFile2 in cFileList2 if cFile2 is in iNameList then else set the end of errorFileList2 to cFile2 & return --未照合リスト end if end repeat set numii to count of LabelFileList repeat with ii from 1 to numii tell application "Finder" delay 0.01 try set label index of ((item ii of LabelFileList) as alias) to 3 --3はイエロー end try end tell end repeat if (errorFileList = {}) and (errorFileList2 = {}) then else tell application "TextEdit" activate make new document set name of front window to "未照合リスト" set text of front document to ("●参照元にしかないアイテム" & return & (errorFileList2 as Unicode text) & return & return & return & "●参照先にしかないアイテム" & return & (errorFileList as Unicode text)) set size of every word of document 1 to 13 end tell end if BeepVolume2() of me activate display dialog "同名のファイルには、" & return & "イエローのラベルが付きます。" & return & return & "拡張子は無視してます。" buttons {"OK"} default button 1 giving up after 55 --return input end run on repChar(origText, targStr, repStr) set {txdl, AppleScript's text item delimiters} to {AppleScript's text item delimiters, targStr} set temp to text items of origText set AppleScript's text item delimiters to repStr set res to temp as text set AppleScript's text item delimiters to txdl return res end repChar --ファイル名から拡張子を外す on retFileNameWithoutExt(fileNameStr) set fLen to length of fileNameStr set revText to (reverse of (characters of fileNameStr)) as string --逆順テキストを作成 set anOffset to offset of "." in revText if anOffset > 2 then set fRes to text 1 thru (fLen - anOffset) of fileNameStr return fRes else set fRes to fileNameStr return fRes end if end retFileNameWithoutExt --ファイル名文字列から拡張子のみ取得する on retExtNameFromFilenameStr(fileNameStr) set fLen to length of fileNameStr set revText to (reverse of (characters of fileNameStr)) as string --逆順テキストを作成 set anOffset to offset of "." in revText if anOffset = 0 then set fRes to "" else if anOffset < 10 then set fRes to text (fLen - anOffset + 1) thru -1 of fileNameStr else set fRes to "" end if return fRes end retExtNameFromFilenameStr on BeepVolume2() set getvolume to get volume settings set outVol to output volume of getvolume set myVol to outVol / (100 / 7) set volume 0.7 --実際に鳴らす音量 数値:0-7まで beep 1 delay 0.5 beep 1 set volume myVol --say "終了しました。" using "Kyoko" end BeepVolume2 |
【使い方】
まず、上の図のように参照元のファイルを選択して、
編集 > コピー
または Command + C
次に参照先のファイルを選択して右クリック、
作成したサービスを選択すると、
照合元と同じ名前のファイルにイエローラベルがついていきます。
(拡張子は無視する仕様になっています。)
ちなみに、参照元は、テキストでも可能。
OS Xの「サービス」を使用して、選択アイテムをリスト表示。
を使用してファイル名を調べて、
同じ名前のファイルを探すことも可能です。
【注意点】
よっぽど変なファイル名の付け方をしなければ大丈夫だと思いますが、
拡張子を間違えて認識し、同じ名前のはずが、
異なる名前として判断する可能性はあります。
参考情報