JPEG image is 1280w * 1024h, 3 color components, 8 bits per sample
JPEG process: Baseline
のような形で返ってきます。
『rdjpgcom』コマンドは、JPEG画像以外のファイルを処理した場合、標準エラー出力に『Not a JPEG file』の文字列を返してくるので、メッセージを『try~on error』で拾えます。
AppleScriptから使う場合はこんな感じでしょうか。
on open drop
repeat with aFile in drop
tell application "Finder"
set fPath to POSIX path of aFile as string
set scpt to "/usr/local/bin/rdjpgcom -verbose " & quoted form of fPath
try
set rslt to do shell script scpt as string
if rslt is not "" then
display dialog name of aFile & return & word 3 of paragraph 2 of rslt
else
display dialog "不明"
end if
on error errStr
display dialog errStr
end try
end tell
end repeat
end open
property DIFF_THRESHOLD : 50
tell application "Adobe Photoshop CS4"
activate
set doc1 to document 1
set doc2 to document 2
set current document to doc1
tell doc1
flatten
select all
copy
end tell
set current document to doc2
tell doc2
flatten
paste
set bits per channel to sixteen
change mode to RGB
set imgLay1 to background layer
set name of imgLay1 to "Image 1"
set imgLay2 to layer 1
set name of imgLay2 to "Image 2"
set blend mode of imgLay2 to difference
duplicate imgLay1
duplicate imgLay2
move 2nd layer to after 3rd layer
tell layer 1
merge
select all
adjust using curves with options {class:curves, curve points:{{0, 0}, {4, 255}}}
adjust using threshold adjustment with options {class:threshold adjustment, level:DIFF_THRESHOLD}
adjust using inversion
end tell
make new art layer with properties {blend mode:lighten}
fill selection with contents {class:RGB color, red:255, green:64, blue:64}
merge layer 1
set name of layer 1 to "Diff"
set opacity of layer 1 to 70
set blend mode of layer 2 to normal
end tell
end tell
tell application "Adobe Photoshop CS4"
set ru to ruler units of settings
set ruler units of settings to cm units
end tell
tell application "Finder"
set srcFold to (choose folder with prompt "クリッピングあり画像(コピー元)のフォルダを選択") as string
set srcFold to srcFold as string
set destFold to (choose folder with prompt "クリッピングなし画像(適用先)のフォルダを選択") as string
repeat with theFile in list folder destFold without invisibles
set theFile to (destFold & theFile) as alias
if not class of ((properties of theFile) as record) is folder then my setLabel(theFile, 2)
end repeat
set destFold to destFold as string
repeat with theFile in list folder srcFold without invisibles
set srcFile to (srcFold & theFile) as alias
if not class of ((properties of srcFile) as record) is folder then
try
set destFile to (destFold & theFile) as alias
my mergePath(srcFile, destFile)
on error
--コピー先のファイルを開けない(存在しない)場合もコピー元に赤ラベルを付ける
my setLabel(srcFile, 2)
end try
end if
end repeat
end tell
tell application "Adobe Photoshop CS4"
set ruler units of settings to ru
end tell
activate me
beep
if my chkLabel(srcFold) or my chkLabel(destFold) then
display dialog "処理に問題のある画像があります。" & return & "双方のフォルダの『赤いラベル』のファイルをチェックして下さい。" with icon 0
else
display dialog "終了しました。"
end if
on mergePath(srcFile, destFile)
tell application "Adobe Photoshop CS4"
activate
open srcFile showing dialogs never
set srcDoc to current document
set pathItem to path items in srcDoc whose kind is clipping
if (count pathItem) is 0 then
my setLabel(srcFile, 2)
close srcDoc
return
end if
--クリッピングパスが存在せず下の行の処理に失敗すると以降の記述が実行されない場合がある?(エラーは出ず再現条件不明)
set cp to entire path of path items in srcDoc whose kind is clipping
close srcDoc
my setLabel(srcFile, 4)
open destFile showing dialogs never
set destDoc to current document
if (count (path items in destDoc whose kind is clipping)) is 0 then
make new path item in destDoc with properties {entire path:cp, name:"Clipping", kind:clipping}
my setLabel(destFile, 4)
close destDoc saving yes
else
close destDoc
end if
end tell
end mergePath
on setLabel(theFile, col)
tell application "Finder"
set label index of theFile to col
end tell
end setLabel
on chkLabel(theFolder)
tell application "Finder"
repeat with theFile in list folder theFolder without invisibles
set theFile to (theFolder & theFile) as alias
if label index of theFile is 2 then return true
end repeat
return false
end tell
end chkLabel
property user : "あなたのユーザ名"
property pass : "パスワード"
tell application "Finder"
set friend to text returned of (display dialog "『あの人』のユーザ名を入力してください。" default answer "") as string
try
--set scpt to "curl --user \"" & user & ":" & pass & "\" -L \"http://twitter.com/friendships/exists.json?user_a=" & friend & "&user_b=" & user & "\""
set scpt to "curl -L \"http://api.twitter.com/1/friendships/exists.json?user_a=" & friend & "&user_b=" & user & "\""
set ret to do shell script scpt
on error
my myError()
end try
set mes to "『" & friend & "』さんは、あなたをfollowして"
if ret is "true" then
display dialog mes & "います。" buttons "OK" default button 1
else if ret is "false" then
display dialog mes & "いません。" buttons "OK" default button 1 with icon 2
else
my myError()
end if
end tell
on myError()
activate me
display dialog "ユーザ名を正しく入力してください。" buttons "OK" default button 1
error number -128
end myError