LoginSignup
0
0

More than 1 year has passed since last update.

JXA(JavaScript で書いた AppleScript)で alert(); を使いたい

Last updated at Posted at 2022-05-07

 なんか「そういうときは displayAlert を使うんだよ」という情報ばかりだったのでつくってしまった。

/**
 * Javascript の alert() のように振る舞う。
 * @param {string} msg 表示したいメッセージ。'\n' で改行できます。
 * @param {string} icon アイコン(("warning" | "informational" | "critical")。規定は "informational")。
 * @param {array} buttons 設置するボタン名の配列(既定は "OK" ひとつ)。
 * @param {string} defaultBtn デフォルトにしたいボタン名(既定は "OK")。
 * @param {string} cancelButton キャンセルボタンにしたいボタン名(既定はなし)。
 * @param {int} givingUpAfter 0 より大きい値を設定すると、その秒数でダイアログを閉じる(既定は 0:閉じない)。
 * @returns 返り値オブジェクト。例:{buttonReturned:OK}
 */
function alert(msg,
    icon = "informational",
    buttons = ["OK"],
    defaultBtn = "OK",
    cancelButton = null,
    givingUpAfter = 0) {

    var app = Application.currentApplication();
    app.includeStandardAdditions = true;

    var params = {
        as: icon,
        buttons: buttons,
        defaultButton: defaultBtn,
        givingUpAfter: givingUpAfter
    };

    if (cancelButton !== null) {
        params.cancelButton = cancelButton;
    }

    return app.displayAlert(msg, params);
}

alert("msg", "informational", ["Yes", "No"], "Yes", "No");
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0