on run
set theDefLoc to POSIX file "/Users/Shared/Downloads"
set theFileType to "public.png,public.jpeg" as text
set AppleScript's text item delimiters to {","}
set theFileTypeList to every text item of theFileType
set theWithPrompt to theFileType & "\nファイルをえらんでください\n"
set theWithPromptMes to "ファイルをドロップしても\n動作します"
open (choose file default location theDefLoc ¬
with prompt theWithPrompt & theWithPromptMes ¬
of type theFileTypeList ¬
invisibles true ¬
with multiple selections allowed without showing package contents)
end run
on open theDropObj
set theErrorPlaceMes to "処理が終了しました" as text
set theApplicationName to name of current application as string
set theDateTime to (do shell script "date +'%Y%m%d_%H_%M_%S'" as string)
set theLogFileName to (theApplicationName & "_" & theDateTime & ".txt") as text
tell application "Finder"
repeat with theObjFiles in theDropObj
try
do shell script "touch /tmp/test1.txt"
my theLogEvent("\nこのファイルは削除しても大丈夫です\n\n", "処理1は正常終了しました", theLogFileName)
on error theErrorMsg number theErrorNum
set theErrorPlaceMes to "Er0001"
my theLogEvent(theErrorPlaceMes & ":" & theErrorMsg & ":" & theErrorNum, theLogFileName)
activate
display dialog (theErrorMsg & ":" & theErrorNum & "\n" & "メールで↓のメッセージをお伝え下さい") ¬
default answer (theErrorPlaceMes & ":" & theErrorMsg & ":" & theErrorNum) ¬
with icon 1 default button 2
set theErrorPlaceMes to "エラーが発生して処理を中断しました:" & theErrorPlaceMes
end try
try
tell current application
do shell script "rm /tmp/test2.txt"
end tell
on error theErrorMsg number theErrorNum
set theErrorPlaceMes to "Er0002"
my theLogEvent("", theErrorPlaceMes & ":" & theErrorMsg & ":" & theErrorNum, theLogFileName)
open (folder "AppleScripts" of folder "Logs" of (path to library folder from user domain))
activate
display dialog (theErrorMsg & ":" & theErrorNum & "\n" & "メールで↓のメッセージをお伝え下さい") ¬
default answer (theErrorPlaceMes & ":" & theErrorMsg & ":" & theErrorNum) ¬
with icon 1 default button 2
set theErrorPlaceMes to "エラーが発生して処理を中断しました:" & theErrorPlaceMes
end try
end repeat
activate
display alert theErrorPlaceMes message "" as informational giving up after 1
end tell
end open
on theLogEvent(theFirstMessage, theLogMessage, theLogFile)
try
tell application "Finder"
make new folder at folder "Logs" of (path to library folder from user domain) with properties {name:"AppleScripts"}
end tell
end try
try
tell application "Finder"
make new file at (folder "AppleScripts" of folder "Logs" of (path to library folder from user domain)) with properties {name:theLogFile}
end tell
end try
try
tell application "Finder"
make new file at (folder "AppleScripts" of folder "Logs" of (path to library folder from user domain)) with properties {name:"_このフォルダは削除しても大丈夫です.txt"}
end tell
end try
do shell script "echo " & quoted form of (theFirstMessage & "\n") & " >> ~/Library/Logs/AppleScripts/" & quoted form of (theLogFile)
do shell script "echo " & quoted form of (theLogMessage & "\n") & " >> ~/Library/Logs/AppleScripts/" & quoted form of (theLogFile)
end theLogEvent