AppleScript名:ポイント数値のテキストをmmに書き換える v4 |
set aRes to " 772.4 x 1082.8 pts" set sizeRes to changePTStoMM(aRes) of me log result –> {strDat:"272.6572 x 382.2284 mm", numDat:{272.6572, 382.2284}} set aRes to "595 x 842 pts (A4)" set sizeRes to changePTStoMM(aRes) of me log result –> {strDat:"210.035 x 297.226 mm", numDat:{210.035, 297.226}} set aRes to " 2242.2 x 1618.58 pts" set sizeRes to changePTStoMM(aRes) of me log result –> {strDat:"210.035 x 297.226 mm", numDat:{210.035, 297.226}} –ポイント数値のテキストをmmに書き換える v4 –問題が見つかったので書き換え(2010/3/12) –超泥縄式の対応だったので、「(A4)」の判型表示が行われないケースにはきちんと対応できていなかった –慌てて直した。ちゃんと文字と数字のアトリビュートを取得しているのでまじめに活用してみた on changePTStoMM(aText) set wList to words of aText set attrList to {} repeat with i in wList set the end of attrList to numChk(i) of me end repeat set aCount to length of wList set aReNumList to {} repeat with i from 1 to (aCount) set anItem to item i of wList set anAttr to item i of attrList if anAttr = true then set the end of aReNumList to (point2mm(anItem as number) of me) end if end repeat –エラー時の対応(多分ないと思うが、一応) if length of aReNumList is not equal to 2 then return false –まじめに数値データから文字列を組み立てて返す set num1 to contents of item 1 of aReNumList set num2 to contents of item 2 of aReNumList set aText to ((num1 as string) & " x " & num2 as string) & " mm" return {strDat:aText, numDat:aReNumList} end changePTStoMM –リストを任意のデリミタ付きでテキストに on makeStrFromListWithDelim(aDelim, aList) set aText to "" set curDelim to AppleScript’s text item delimiters set AppleScript’s text item delimiters to aDelim set aText to aList as text set AppleScript’s text item delimiters to curDelim return aText end makeStrFromListWithDelim –ポイントからmmへの変換 on point2mm(a) return (a * 0.353) –1ポイント=0.353mm end point2mm –数値かどうか調べる on numChk(aNum) set aClass to (class of aNum) as string if aClass = "number" or aClass = "double" or aClass = "integer" or aClass = "real" then return true else if aClass = "string" or aClass = "text" or aClass = "unicode text" then try set bNum to aNum as number return true on error return false end try end if end numChk on trimStrFromTo(aStr, fromStr, toStr) –fromStrは前から探す if fromStr is not equal to "" then set sPos to (offset of fromStr in aStr) + 1 else set sPos to 1 end if –toStrは後ろから探す if toStr is not equal to "" then set b to (reverse of characters of aStr) as string set ePos to (offset of toStr in b) set ePos to ((length of aStr) – ePos) else set ePos to length of aStr end if set aRes to text sPos thru ePos of aStr return aRes end trimStrFromTo |
More from my site
(Visited 91 times, 1 visits today)