on run
set theWithPrompt to "タブテキストをメールリンクに変換"
tell application "Finder"
set theDefaultLocation to (container of (path to me)) as alias
end tell
set theFileTypeList to "public.plain-text,com.apple.traditional-mac-plain-text" as text
set AppleScript's text item delimiters to {","}
set theFileTypeList to every text item of theFileTypeList
open (choose file default location theDefaultLocation ¬
with prompt theWithPrompt ¬
of type theFileTypeList ¬
invisibles true ¬
with multiple selections allowed without showing package contents)
end run
on open objOpenDrop
set theFileAlias to objOpenDrop as alias
set theUnixPass to POSIX path of theFileAlias as text
set theData to (do shell script "cat '" & theUnixPass & "'") as «class utf8»
set AppleScript's text item delimiters to {"\r"}
set retListVal to (every text item of theData) as list
set numListLine to count of retListVal
set numLine to 1 as number
set numTabIndex to 1 as number
set theLineData1 to "" as text
set theLineData2 to "" as text
set theLineData3 to "" as text
set theHtmlData to "<!-- ここからEmailアドレステーブル -->\r"
set theHtmlData to theHtmlData & "<style type=\"text/css\" media=\"screen\">div.bordertable{width: 80%;} .bordertable table , .bordertable th , .bordertable td {font-size: 12px;border: solid 1px #666666;padding: 3px;border-collapse: collapse;overflow: inherit;word-wrap: break-word;} .bordertable th.mailname{font-size: small;text-align: left;} .bordertable a.emailadd{font-family: monospace;font-style: normal;word-break: keep-all;} .bordertable p{font-size: small;text-align: center;} .bordertable input{width: 88px;border-width: 0px;border-style: none;height: auto;width: 60px;padding: 0px;margin: 0px;font-size: small;text-align: right;}</style>" as text
set theHtmlData to theHtmlData & "<div class=\"bordertable\">\r<form>" as text
set theHtmlData to theHtmlData & "<p>LiveMailを利用している人はWをクリック</p>\r" as text
set theHtmlData to theHtmlData & "<table>" as text
set theHtmlData to theHtmlData & "<caption>メールアドレス一覧|個人情報につき取り扱いには注意しましょう</caption>" as text
set theHtmlData to theHtmlData & "<thead title=\"見出し\"><tr><th>氏名</th><th>所属</th><th colspan=\"3\">メール</th></tr></thead>" as text
set theHtmlData to theHtmlData & "<tbody title=\"メールアドレス一覧\">" as text
repeat numListLine times
set theDataListLine to (item numLine of retListVal) as text
set AppleScript's text item delimiters to {"\t"}
set theDataListLineData to every text item of theDataListLine as list
set numListLineCnt to (count of theDataListLineData) as number
set theLineData1 to (item 1 of theDataListLineData) as text
set theLineData2 to (item 2 of theDataListLineData) as text
set theLineData3 to (item 3 of theDataListLineData) as text
set theOrgEmail to theLineData3 as text
set theLinkName to ("【" & theLineData2 & "】" & theLineData1 & "さん") as text
set theInputText to ("【" & theLineData2 & "】" & theLineData1 & "さん<" & theOrgEmail & ">") as text
set theLinkNameMac to my doUrlEncode(theLinkName) as text
set theLinkNameMac to my doReplace(theLinkNameMac, "+", "") as text
set theLinkNameMac to (theLinkNameMac & "%3C" & theOrgEmail & "%3E") as text
set theLinkNameWin to my doSJISencode(theLinkName) as text
set theLinkNameWin to (theLinkNameWin & "%3C" & theOrgEmail & "%3E") as text
set theLinkBodyName to ("TO:\r【" & theLineData2 & "】" & theLineData1 & "さん") as text
set theLinkBodyNameMac to my doUrlEncode(theLinkBodyName) as text
set theHtmlData to theHtmlData & "<tr>\r" as text
set theHtmlData to theHtmlData & "<th title=\"" & theLineData1 & "さんのメールアドレスリンク\" class=\"mailname\">" as text
set theHtmlData to (theHtmlData & "<a rel=\"nofollow\" href=\"mailto:" & theLinkNameMac & "?body=" & theLinkBodyNameMac & "\" tabindex=\"" & (numTabIndex) as text) & "\" title=\"" & theLineData1 & "さんの名前をメール本文に入れます\" target=\"_blank\">" & theLineData1 & "</a></th>" as text
set theHtmlData to theHtmlData & "<td title=\"所属\">" & theLineData2 & "</td>" as text
set theHtmlData to theHtmlData & "<td title=\"所属+名前形式のメールリンク\"> " as text
set theHtmlData to (theHtmlData & "<a rel=\"nofollow\" href=\"mailto:" & theLinkNameMac & "\" title=\"所属+" & theLineData1 & "さん+メールアドレス。\" tabindex=\"" & (numTabIndex + 1) as text) & "\" target=\"_blank\">M</a>" as text
set theHtmlData to theHtmlData & " | " as text
set theHtmlData to (theHtmlData & "<a rel=\"nofollow\" href=\"mailto:" & theLinkNameWin & "\" title=\"所属+" & theLineData1 & "さん+メールアドレス。WindowsLiveメールを利用している方はこちらをクリック\" tabindex=\"" & (numTabIndex + 2) as text) & "\" target=\"_blank\">W</a>" as text
set theHtmlData to theHtmlData & " </td>" as text
set theHtmlData to theHtmlData & "<td title=\"メールアドレスだけのリンク\">" as text
set theHtmlData to (theHtmlData & "<a rel=\"nofollow\" href=\"mailto:" & theOrgEmail & "\" title=\"" & theOrgEmail & "\" tabindex=\"" & (numTabIndex + 3) as text) & "\" class=\"emailadd\" target=\"_blank\">" & theOrgEmail & "</a></td>" as text
set theHtmlData to theHtmlData & "<td title=\"コピペ用のテキストエリア\">" as text
set theHtmlData to (theHtmlData & "<input type=\"Text\" name=\"emailtext\" value=\"" & theInputText & "\" tabindex=\"" & (numTabIndex + 4) as text) & "\" onclick=\"this.select(0,this.value.length)\">" as text
set theHtmlData to theHtmlData & "</td>" as text
set theHtmlData to theHtmlData & "\r</tr>\r" as text
set numLine to numLine + 1 as number
set numTabIndex to numTabIndex + 5 as number
set theLineData1 to "" as text
set theLineData2 to "" as text
set theLineData3 to "" as text
end repeat
set theHtmlData to theHtmlData & "</tbody>\r"
set theHtmlData to theHtmlData & "</table>\r</form>\r</div>\r"
set theHtmlData to theHtmlData & "<!-- ここまでEmailアドレステーブル -->\r"
tell application "TextEdit" to launch
tell application "TextEdit"
make new document with properties {text:theHtmlData}
end tell
tell application "TextEdit" to activate
end open
on doUrlEncode(str)
set scpt to "php -r 'echo urlencode(\"" & str & "\");'"
return do shell script scpt
end doUrlEncode
on doSJISencode(str)
set scpt to ("php -r 'echo urlencode(mb_convert_encoding(\"" & str & "\"" & ",\"SJIS\", \"auto\"));'") as text
return do shell script scpt
end doSJISencode
to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace