JXA:显示带有自定义图标的对话框
JXA: display dialog with custom icon
使用 AppleScript,我们可以轻松显示带有自定义图标的对话框:
display dialog "Test" with icon POSIX file "{{path_to_our_icon}}"
我们如何使用 JXA(JavaScript 用于自动化)做同样的事情? official documentation 似乎没有涵盖这一点。它只告诉我们如何使用其中一个预定义图标。
如果 SDEF 字典指定类型为 file 的参数,您需要在 Path() 构造函数中包含完整路径字符串。
(有关 Path() 的更多信息,请参阅自动化发行说明 JavaScript 中的 'Paths' 下方)
(function () {
'use strict';
var a = Application.currentApplication(),
sa = (a.includeStandardAdditions = true, a);
sa.displayDialog('Test', {
defaultAnswer: 'Next question ?',
buttons: ['OK', 'Cancel'],
defaultButton: 'OK',
cancelButton: 'Cancel',
withTitle: 'Test dialog',
withIcon: Path('/System/Library/Frameworks/Automator.framework/Versions/A/Resources/Automator.icns')
});
})();
使用 AppleScript,我们可以轻松显示带有自定义图标的对话框:
display dialog "Test" with icon POSIX file "{{path_to_our_icon}}"
我们如何使用 JXA(JavaScript 用于自动化)做同样的事情? official documentation 似乎没有涵盖这一点。它只告诉我们如何使用其中一个预定义图标。
如果 SDEF 字典指定类型为 file 的参数,您需要在 Path() 构造函数中包含完整路径字符串。
(有关 Path() 的更多信息,请参阅自动化发行说明 JavaScript 中的 'Paths' 下方)
(function () {
'use strict';
var a = Application.currentApplication(),
sa = (a.includeStandardAdditions = true, a);
sa.displayDialog('Test', {
defaultAnswer: 'Next question ?',
buttons: ['OK', 'Cancel'],
defaultButton: 'OK',
cancelButton: 'Cancel',
withTitle: 'Test dialog',
withIcon: Path('/System/Library/Frameworks/Automator.framework/Versions/A/Resources/Automator.icns')
});
})();