var folder; var fontarray = { "A-OTF じゅん Pro,101":"A-OTF 新ゴ Pro,R", "A-OTF じゅん Pro,34":"A-OTF 新ゴ Pro,M", "Courier OS,Regular":"AlfxMono+じゅん101,", }; for (var i in fontarray) { var fa = fontarray[i].split(/,/); if (fa[1] == null) fa[1] = ""; for (var f = 0; f < app.textFonts.length; f++) { if (app.textFonts[f].family == fa[0] && app.textFonts[f].style == fa[1]) { fontarray[i] = app.textFonts[f]; break; } } if (!(fontarray[i] instanceof TextFont)) { alert("フォント " +fontarray[i] + " がありません"); } } var dialog = new Window("dialog", "フォント変更", [100,100,480,245]); dialog.okButton = dialog.add("button", [180, 100, 180+50, 100+25], "開始", { name: "ok" }); dialog.cancelButton = dialog.add("button", [260, 100, 260+50, 100+25], "閉じる", { name: "cancel"}); dialog.folderlabel = dialog.add("statictext", [20, 70, 20+450, 70+25], "フォルダを選択してください"); dialog.folderButton = dialog.add("button", [20, 100, 20+50, 100+25], "参照"); dialog.folderButton.onClick = function() { folder = Folder.selectDialog("変換対象画像のあるフォルダを選択"); if (folder != null) { dialog.folderlabel.text = folder.absoluteURI; } else { dialog.folderlabel.text = "フォルダを選択してください"; } } dialog.okButton.onClick = function() { if (dialog.folderlabel.text == "フォルダを選択してください") { alert("フォルダが選択されていません"); return false; } var list = folder.getFiles(); var count = 0; for (var i = 0; i < list.length; i++) { if (list[i] instanceof File && list[i].name.match(/.(eps|ai)$/i)) { replaceFont(list[i], fontarray); count++; } } alert(count + "個のファイルの変換が完了しました"); dialog.close(); } dialog.cancelButton.onClick = function() { dialog.close(); } dialog.show(); //var myDocument = app.activeDocument; //replaceFont(myDocument, fontarray); function replaceFont(file, array) { var myDocument = app.open(file); for (var f = 0; f < myDocument.textFrames.length; f++) { for (var r = 0; r < myDocument.textFrames[f].characters.length; r++) { var myfont = myDocument.textFrames[f].characters[r].textFont; if (array[myfont.family + "," + myfont.style] instanceof TextFont) { myDocument.textFrames[f].characters[r].textFont = array[myfont.family + "," + myfont.style]; } } } myDocument.close(SaveOptions.SAVECHANGES); }