Created
September 16, 2020 06:53
-
-
Save UskeS/31bb89d7c0f98cd13dc719e8213432e1 to your computer and use it in GitHub Desktop.
[ExtendScript] [InDesign] 括弧数字を閉じたり開いたりするスクリプト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 選択状態のバリデーション | |
*/ | |
if (app.documents.length === 0) myError("NOT_OPENED_DOCUMENT"); | |
if (app.documents[0].selection.length === 0) myError("INVALID_SELECTION"); | |
/** | |
* メイン処理 | |
*/ | |
var doc = app.activeDocument; | |
var sel = doc.selection; | |
for (var i=0; i<sel.length; i++) { | |
if (!sel[i].hasOwnProperty("changeGrep")) continue; | |
app.doScript(main, ScriptLanguage.JAVASCRIPT, sel[i], UndoModes.ENTIRE_SCRIPT); | |
} | |
/** | |
* 括弧数字をテキストに分解する | |
* | |
* @param {Object} tgt 検索置換対象オブジェクト | |
*/ | |
function main(tgt) { | |
app.findGrepPreferences = app.changeGrepPreferences = null; | |
var count = 1; | |
for (var i=0x2474; i<0x2488; i++) { | |
app.findGrepPreferences.findWhat = "\\x{" + i.toString(16) + "}"; | |
app.changeGrepPreferences.changeTo = "(" + count + ")"; | |
tgt.changeGrep(); | |
count ++; | |
} | |
} | |
/** | |
* エラー終了メソッド | |
* | |
* @typedef {string} erCode | |
* @property {string} NOT_OPENED_DOCUMENT ドキュメントが開かれていない状態 | |
* @property {string} INVALID_SELECTION 選択状態が正しくない状態 | |
*/ | |
function myError(erCode) { | |
var erMes = { | |
"NOT_OPENED_DOCUMENT": "ドキュメントが開かれていません", | |
"INVALID_SELECTION": "選択対象が正しくありません。テキストを選択してから実行してください", | |
}; | |
alert(erCode + ": " + erMes[erCode]); | |
exit(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 選択状態のバリデーション | |
*/ | |
if (app.documents.length === 0) myError("NOT_OPENED_DOCUMENT"); | |
if (app.documents[0].selection.length === 0) myError("INVALID_SELECTION"); | |
/** | |
* メイン処理 | |
*/ | |
var doc = app.activeDocument; | |
var sel = doc.selection; | |
for (var i=0; i<sel.length; i++) { | |
if (!sel[i].hasOwnProperty("changeGrep")) continue; | |
app.doScript(main, ScriptLanguage.JAVASCRIPT, sel[i], UndoModes.ENTIRE_SCRIPT); | |
} | |
/** | |
* 括弧と数字の組み合わせを連結する | |
* | |
* @param {Object} tgt 検索置換対象オブジェクト | |
*/ | |
function main(tgt) { | |
app.findGrepPreferences = app.changeGrepPreferences = null; | |
var count = 1; | |
for (var i=0x2474; i<0x2488; i++) { | |
app.findGrepPreferences.findWhat = "(" + count + ")"; | |
app.changeGrepPreferences.changeTo = "\\x{" + i.toString(16) + "}"; | |
tgt.changeGrep(); | |
count ++; | |
} | |
} | |
/** | |
* エラー終了メソッド | |
* | |
* @typedef {string} erCode | |
* @property {string} NOT_OPENED_DOCUMENT ドキュメントが開かれていない状態 | |
* @property {string} INVALID_SELECTION 選択状態が正しくない状態 | |
*/ | |
function myError(erCode) { | |
var erMes = { | |
"NOT_OPENED_DOCUMENT": "ドキュメントが開かれていません", | |
"INVALID_SELECTION": "選択対象が正しくありません。テキストを選択してから実行してください", | |
}; | |
alert(erCode + ": " + erMes[erCode]); | |
exit(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment