2017-05-14 71 views
0

使用AppleScript显示对话框,我们可以很容易地显示与自定义图标对话框:JXA:与自定义图标

display dialog "Test" with icon POSIX file "{{path_to_our_icon}}" 

我们怎样才能做同样的JXA(JavaScript进行自动化)? official documentation似乎没有涵盖这一点。它只告诉我们如何使用其中一个预定义的图标。

回答

1

如果SDEF词典指定了文件类型的参数,则需要包装在Path()构造函数中的完整路径字符串。

(更多关于路径()下看到在JavaScript自动化发行说明 '路径')

(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') 
    }); 
})();