InDesign 表のセル内容が負数の場合、マイナスを削除し「▲」にする AppleScript
2-5 02 表のセル内容が負数の場合、マイナスを削除し「▲」にする(P.128)
- 作者: (株)シータス,古籏一浩
- 出版社/メーカー: 技術評論社
- 発売日: 2008/11/25
- メディア: 大型本
- 購入: 5人 クリック: 91回
- この商品を含むブログ (8件) を見る
=== 書籍の JavaScript を AppleScript で書き直します ===
部品作製
- InDesign ドキュメント
- AppleScript ハンドラ
- tableList(myObj) -- オブジェクト内の全ての表を返す
- tableSize(myTable) -- 表の大きさを返す(横,縦のセル数)
- tCell(myTable, cIdx, rIdx) -- [cIdx]番目の項目の[rIdx]行目のセルオブジェクトを返す
上記ハンドラは、以下のエントリで実装済みです。
以下のハンドラも前回のものを少し修正するだけで対応できます。
-- 表内の全てのセルを調査する on tableWalk(myTable) set myColor to getColor("KINAKA") set {cMax, rMax} to tableSize(myTable) repeat with rIdx from 1 to rMax repeat with cIdx from 1 to cMax set myCell to tCell(myTable, cIdx, rIdx) --minus2red(myCell, myColor) minus2sankaku(myCell) -- <== ※ end repeat end repeat end tableWalk -- セルの1文字目が「-」なら、「-」を「▲」に置換する on minus2sankaku(myCell) tell application "Adobe InDesign CS6" if contents of first character of myCell is "-" then set character 1 of myCell to "▲" -- <== ※ end if end tell end minus2sankaku
部品が揃ったので、実行
on run {} my setUp() my main() my tearDown() end run on setUp() tell document 1 of application "Adobe InDesign CS6" select every text frame of page 1 end tell end setUp on main() -- 色を追加 --addProcessColor("KINAKA", {0, 100, 100, 0}) -- 指定したテキストフレーム内の全てのテーブルオブジェクトを取得する tell document 1 of application "Adobe InDesign CS6" set myTF to text frame 1 of page 1 end tell set tableList to tableList(myTF) -- テーブル数分繰り返す set loop to number of tableList tell application "Adobe InDesign CS6" repeat with i from 1 to loop tableWalk(item i of tableList) of me end repeat end tell end main on tearDown() activate display dialog "Script 終了" giving up after 3 end tearDown
実行結果
- OS X 10.8.5
- Adobe InDesign CS6, version: 8.0.2.413