ScriptUI: Always honor Cancel/Esc in onClose validations

When you need to validate user input in an edittext field, it’s not enough to do so in its onChange event — you must also validate it in the dialog’s onClose. It’s the only way to stop the dialog from closing after a click on the OK button, so that the user has a chance to correct their input. But what if that close event occurred because of an explicit user action to simply dismiss the dialog, like clicking the Cancel button?

Continue reading →

Controlling measurementUnits

From pixels to points to ciceros, InDesign allows users to pick from 15 different measurement units to use in various places of their documents. Thanks to this versatility, it can sometimes be hard to predict how a script will act in a measurement unit environment even slightly different from yours.

Where are these measurement units?

There are three major places where measurement units could vary depending on the user environment:

Continue reading →

scriptPreferencesをバッチ変更→復元

スクリプト本体の実行前にユーザ設定値を変更しておき、本体実行後に元に戻す、という処理が頻出する。

特によくあるのが app.scriptPreferences の設定。 enableRedraw はほとんどの場合で disable したいだろうし、 measurementUnit は意図しない設定になっていると絶対値の組み込まれたアルゴリズムが不具合を起こす。

この辺の〈保持→変更→復元〉という処理を main() などに直接入れちゃうと煩雑なので、 scriptSettings.alter()scriptSettings.revert() で本体ルーチンを挟むだけでいいようにメソッド化してみた。

Continue reading →