function setRuby(words, rubystr, rubytype) { for (var i = 0; i < words.length; i++) { if (words[i].characters[0].rubyFlag == false) { // すでにルビがある場合は触らない words[i].rubyString = rubystr; words[i].rubyType = rubytype; words[i].rubyFlag = true; } } } var myDocument = app.activeDocument; if (myDocument.selection[0] instanceof TextFrame) { var tf = myDocument.selection[0]; app.findGrepPreferences = NothingEnum.nothing; app.findGrepPreferences.findWhat = "楽(?=しく)"; // 後方肯定 setRuby(tf.findGrep(), "たの", RubyTypes.PER_CHARACTER_RUBY); app.findTextPreferences = NothingEnum.nothing; app.findTextPreferences.findWhat = "作成方法"; setRuby(tf.findText(), "さくせいほうほう", RubyTypes.GROUP_RUBY); } else { alert("対象テキストフレームを選択してください。"); }