导入基础框架后,Applescript无法识别路径

时间:2018-11-07 08:20:18

标签: applescript

我可以使用以下代码在AppleScript中显示自定义图标

set iconPath to "/Users/dutt/myFolder/AppIcon.icns" as POSIX file
set theContent to " hi"
display dialog theContent with icon file iconPath with title "Hello" buttons {"Cancel", "Ok"} default button "Ok"

当我使用下面的代码导入基础时,它抛出了不包含图标的错误文件

use framework "Foundation"
use scripting additions
set iconPath to "/Users/dutt/myFolder/AppIcon.icns" as POSIX file
    set theContent to " hi"
    display dialog theContent with icon file iconPath with title "Hello" buttons {"Cancel", "Ok"} default button "Ok"

我认为这与路径问题有关,使用基础框架后,Apple脚本无法获取图标路径

2 个答案:

答案 0 :(得分:1)

此问题是由您开始在AppleScript中实现Objective-C框架后解决文件引用的方式引起的。

解决方案是使用强制来构建文件引用。因此,请更改:

icon file iconPath

收件人:

icon (iconPath as alias)

或者甚至有必要进行更改:

set iconPath to "/Users/dutt/myFolder/AppIcon.icns" as POSIX file

收件人:

set iconPath to "/Users/dutt/myFolder/AppIcon.icns"

然后在您的display dialog命令中构建文件引用,如下所示:

icon (iconPath as POSIX file as alias)

答案 1 :(得分:1)

我的建议是使用相对的HFS路径,path to home folder指向当前用户的主文件夹。

这避免了POSIX路径-POSIX文件-别名跳舞,并且可以使用Foundation和不使用set iconPath to alias ((path to home folder as text) & "myFolder:AppIcon.icns") set theContent to " hi" display dialog theContent with icon iconPath with title "Hello" buttons {"Cancel", "Ok"} default button "Ok"

file

请注意在with icon之后缺少的Compliance pdf1.7 Result Document does not conform to PDF/A. Details Validating file "foo.pdf" for conformance level pdf1.7 The name Xf1 of a xobject resource is unknown. The document does not conform to the requested standard. The document doesn't conform to the PDF reference (missing required entries, wrong value types, etc.). The document's meta data is either missing or inconsistent or corrupt. The document does not conform to the PDF 1.7 standard. 关键字