“POSIX文件”适用于Applescript编辑器,而不适用于XCode

时间:2012-02-11 07:04:33

标签: applescript xcode4.2 applescript-objc

试试这个:

  1. 制作一个新的XCode4 Applescript项目。在委托中,粘贴此代码:

    on doIt_(sender)
        set goodHFSLoc to (path to desktop folder)
        set test1 to (POSIX path of goodHFSLoc)
        log "test1:"&test1
        set theJSPath to "/Users/dave/Desktop/MakeTSLabels.js"
        set jsHFSFile to (POSIX file theJSPath)
        set test2 to (POSIX path of jsHFSFile)
    end doIt_
    
  2. 将此方法挂钩到UI窗口中的按钮。

  3. 运行程序
  4. 单击按钮,您将收到此错误:

    Can’t get POSIX path of class "NSObject".
    
  5. 将相同的代码(减去“on”和“end”行)放入AppleScript编辑器中,运行正常。
  6. 显然,ApplescriptObjC中的“POSIX文件”不会将文件对象作为语言规范requires。相反,它制作了一个NSObject。

    我需要有一个applescript文件说明符来提供给Adobe Illustrator的do javascript命令,我需要使用NSBundle的函数来获取javascript文件,该文件打包在我的应用程序包中。

    我做错了吗?

1 个答案:

答案 0 :(得分:1)

您会在 Finder 系统事件 tell语句中看到相同的行为。对于ASObjC,解决方案是相同的 - 您需要将其用作强制:

set jsHFSFile to (theJSPath as POSIX file)