以 JXA 脚本的工作表形式显示的警报永远不会解除

问题描述

我正在尝试使用 JXA 以表格形式呈现警报。它在 AppleScript 中按预期工作,但在运行等效的 JavaScript 时,工作表永远不会关闭

要重现,请使用“运行 AppleScript”工作流程在 Automator 中运行:

use framework "Cocoa"
 
on show(title as string,msg as string)
    set alert to current application's NSAlert's new()
    tell alert
        its setMessageText:title
        its set@R_634_4045@iveText:(msg)
        its beginSheetModalForWindow:(current application's NSApp's mainWindow()) completionHandler:(missing value)
    end tell
end show
 
show("test","test")

然后尝试使用“运行 JavaScript”在不同的工作流中运行它:

ObjC.import("Cocoa");
 
function show(title,msg) {
    let alert = $.NSAlert.new;
    alert.messageText = title;
    alert.@R_634_4045@iveText = msg;
    alert.beginSheetModalForWindowCompletionHandler($.NSApp.mainWindow,null);
}
 
show("test","test");

这里有我遗漏的步骤吗?在 beginSheetModalForWindow:completionHandler: 的文档中,它指出:

请注意,在完成处理程序中不再需要调用 orderOut:。如果您不关闭警报,它会在完成处理程序完成后为您完成。

https://developer.apple.com/documentation/appkit/nsalert/1524296-beginsheetmodalforwindow

在撰写本文时,我正在运行最新版本的 macOS,11.1。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)