macOS 10.15でバンドルされなくなった「ヒラギノ角ゴProN W3」「ヒラギノ角ゴProN W6」がKeynote書類中に指定されていたら、それぞれ「ヒラギノ角ゴシック W3」「ヒラギノ角ゴシック W6」に置換するAppleScriptです。
現在オープン中の最前面のKeynote書類を走査して、全スライド中のオブジェクトの内容を取得し、text item、shape、table中に指定されているフォントを置換するようになっています。また、group化されたこれらのオブジェクトを再帰で取得するようになっています。
ただし、グラフ(chart)中の文字のフォントについてはAppleScriptからアクセスできないため、フォントの置換は行えません。このあたりでミソがついて、完全自動でヒラギノ角ゴProNを置換できるわけではないので、少々残念(KeynoteのAppleScript用語辞書の仕様の問題)な結果に。
また、別にこれらのフォントを置換しなくても実害はないので、置換しても単に気分の問題だけでしょう。
AppleScript名:再帰でKeynote書類上のフォントを置換する(グループ対応) |
— Created 2019-11-14 by Takaaki Naganoya — 2019 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" property allText : {} property allShape : {} property allTable : {} set searchFont to {"HiraKakuProN-W6", "HiraKakuProN-W3"} tell application "Keynote" tell front document set sCount to count every slide repeat with ii from 1 to sCount set current slide to slide ii tell current slide getEveryTextAndShapes() of me –Text Item、Shapeのフォント置換ループ set tList to allText & allShape repeat with i in tList set aClass to class of i –if aClass is not equal to default title item then set aFont to font of object text of i set aText to (object text of i) if aFont is in searchFont and aText is not equal to "" then if aFont ends with "-W6" then set font of object text of i to "HiraginoSans-W6" else if aFont ends with "-W3" then set font of object text of i to "HiraginoSans-W3" end if end if –end if end repeat –Table内の全セルのフォント置換ループ repeat with iii in allTable tell iii set cList to every cell repeat with i in cList –Loop by cells set aFont to font name of i set aText to (value of i) if aFont is in searchFont then if aFont ends with "-W6" then set font name of i to "HiraginoSans-W6" else if aFont ends with "-W3" then set font name of i to "HiraginoSans-W3" end if end if end repeat end tell end repeat end tell end repeat end tell end tell on getEveryTextAndShapes() set allText to {} set allShape to {} set allTable to {} tell application "Keynote" tell front document tell current slide set gList to every group set i1List to every text item set i2List to every shape set i3List to every table if i1List is not equal to {} then set allText to allText & i1List if i2List is not equal to {} then set allShape to allShape & i2List if i3List is not equal to {} then set allTable to allTable & i3List prepareGroup(gList) of me end tell end tell end tell end getEveryTextAndShapes –Dig into groups by recursive call on prepareGroup(gList) tell application "Keynote" tell front document tell current slide repeat with i in gList tell i set g2List to every group set i1List to every text item set i2List to every shape set i3List to every table if i1List is not equal to {} then set allText to allText & i1List if i2List is not equal to {} then set allShape to allShape & i2List if i3List is not equal to {} then set allTable to allTable & i3List prepareGroup(g2List) of me end tell end repeat end tell end tell end tell end prepareGroup |
More from my site
(Visited 141 times, 1 visits today)