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