iWork ‘09のKeynote 5.x上で文字オブジェクトをコピーし、実行すると白フチ文字に変換してKeynote上にペーストする(趣味の)AppleScriptです。
まずは、Keynote上で文字オブジェクトをコピーして本Scriptを実行。

クリップボードに入っているデータ(Ritch Text Format)をテキストエディットの新規書類にペースト。テキストエディット上で書式などを分析します。分析したら、用済みのテキストエディット書類は破棄。
テキストエディット上で得られた情報をもとに、今度はIllustrator CS3上で同様にオブジェクトを組み立て、白フチ文字を作成。白フチ文字のオブジェクトをコピーして、Illustrator書類を破棄します。
最後に、Keynoteを最前面に持ってきてSystem Eventsで(GUI Scriptingで)ペースト操作を実行。


以前に作成しておいたルーチンに一部手を加えて、縦方向の文字(1文字ごとに改行)でも、横方向の文字(通常)でも対応します。ただし、本バージョンではオリジナルのフォント情報までは白フチ文字に反映していません。

| スクリプト名:Keynote上でコピーされたテキストオブジェクトの内容をTextEditで解析してIllustratorで白フチ文字を作成してKeynoteにペースト |
–何もコピーされていなければリターン set a to the clipboard if a = “” then return
–Text Editで新規ドキュメントを作成してコピーされていたデータをコピー tell application “TextEdit“ set aDoc to make new document activate end tell
tell application “System Events“ tell process “TextEdit“ keystroke “v“ using {command down} end tell end tell
–TextEditの書類上から各種情報を取得する tell application “TextEdit“ tell text of aDoc set colorList to color of every attribute run set fontList to font of every attribute run set sizeList to size of every attribute run set textList to characters of every attribute run set itemCount to length of colorList set contList to {} repeat with i from 1 to itemCount set aRec to {textData:(item i of textList) as string, colorData:item i of colorList, fontData:item i of fontList, sizeData:item i of sizeList} set the end of contList to aRec end repeat end tell end tell
tell application “TextEdit“ tell document 1 close without saving end tell end tell
set aDirection to detectTextDirection(textList) of me –> “vertical” / “horizontal”
set aFontName to contents of item 1 of fontList set aSize to contents of item 1 of sizeList set aLineWidth to aSize / 8 set aLineWidth to round aLineWidth rounding up
set aCon to textList as string set aCon to repChar(aCon, ASCII character 10, “”) of me set aColor to item 1 of colorList set rColor to (item 1 of aColor) / 256 set rColor to round rColor rounding down set gColor to (item 2 of aColor) / 256 set gColor to round gColor rounding down set bColor to (item 3 of aColor) / 256 set bColor to round bColor rounding down set colorList to {rColor, gColor, bColor}
makeTextGraphicWithEdgeLine(aCon, aSize, aLineWidth, aDirection, aFontName, colorList) of me
tell application “Keynote“ activate end tell
tell application “System Events“ tell process “Keynote“ keystroke “v“ using {command down} end tell end tell
–以下、サブルーチン
–Attribute runsのテキストデータの並びから、Keynote上で縦書き/横書きだったかの判定を行う on detectTextDirection(aList) set normCount to 0 set retCount to 0 log aList repeat with i in aList set jj to contents of (item 1 of i) set j to id of (contents of jj) –display dialog (string id of j) if (j = 10) or (j = 13) then set retCount to retCount + 1 else set normCount to normCount + 1 end if end repeat set vhCalc to (retCount / normCount) if vhCalc > 0.5 then return “vertical“ else return “horizontal“ end if end detectTextDirection
on makeTextGraphicWithEdgeLine(aCon, aSize, aLineWidth, aDirection, aFontName, colorList) copy colorList to {rColor, gColor, bColor} using terms from application “Adobe Illustrator“ tell application “Adobe Illustrator“ set aDoc to make new document with properties {color space:RGB} tell aDoc setOriginToLeftCorner() of me set aGroup to make new group item set aFrame1 to make new text frame at the end of aGroup tell aFrame1 set position to {0, 0} set contents to aCon if aDirection = “vertical“ then set text orientation to vertical else if aDirection = “horizontal“ then set text orientation to horizontal end if tell every character set size to aSize –set font to aFontName set stroke weight to aLineWidth –ふちどり線の太さ set stroke color to {red:255, green:255, blue:255} –白 end tell end tell set aFrame2 to make new text frame at the beginning of aGroup tell aFrame2 set contents to aCon set position to {0, 0} if aDirection = “vertical“ then set text orientation to vertical else if aDirection = “horizontal“ then set text orientation to horizontal end if tell every character set size to aSize –set font to aFontName set stroke weight to 0.0 set fill color to {red:rColor, green:gColor, blue:bColor} end tell end tell set selection to aGroup copy –ふちどり文字をクリップボードにコピー close saving no –Illustratorの書類を破棄する end tell end tell end using terms from end makeTextGraphicWithEdgeLine
–Illustratorの原点座標を変更する on setOriginToLeftCorner() using terms from application “Adobe Illustrator“ tell application “Adobe Illustrator“ tell document 1 set aHeight to height set ruler origin to {0, aHeight} end tell end tell end using terms from end setOriginToLeftCorner
–Written By Philip Aker –文字置換ルーチン 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
|
|
▼新規書類に ▼カーソル位置に ▼ドキュメント末尾に
|