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

发布于 2025-01-05 06:22:48 字数 970 浏览 5 评论 0原文

试试这个:

  1. 创建一个新的 XCode4 Applescript 项目。在委托中,粘贴以下代码:

    on doIt_(发件人)
        将 goodHFSLoc 设置为(桌面文件夹的路径)
        将 test1 设置为(goodHFSLoc 的 POSIX 路径)
        记录“测试1:”和测试1
        将 JSPath 设置为“/Users/dave/Desktop/MakeTSLabels.js”
        将 jsHFSFile 设置为(POSIX 文件 theJSPath)
        将 test2 设置为(jsHFSFile 的 POSIX 路径)
    结束 doIt_
    
  2. 将此方法挂钩到 UI 窗口中的按钮。

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

    无法获取类“NSObject”的 POSIX 路径。
    
  5. 将相同的代码(减去“on”和“end”行)放入 AppleScript 编辑器中,它运行良好。

显然,ApplescriptObjC 中的“POSIX 文件”不会将文件对象作为语言规范需要。相反,它创建一个 NSObject。

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

我做错了什么吗?

Try this:

  1. Make a new XCode4 Applescript project. In the delegate, paste this code:

    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. Hook this method up to a button in the UI window.

  3. Run the program
  4. Click the button, and you should get this error:

    Can’t get POSIX path of class "NSObject".
    
  5. Put the same code (minus the "on" and "end" lines) into AppleScript editor, and it runs fine.

Apparently, "POSIX file" in ApplescriptObjC doesn't make a file object as the language specification requires. Instead it makes an NSObject.

I need to have an applescript file specifier to provide to Adobe Illustrator's do javascript command, and I need to use NSBundle's functions to get the javascript file, which is packaged in my application bundle.

Am I doing something wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万水千山粽是情ミ 2025-01-12 06:22:48

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

set jsHFSFile to (theJSPath as POSIX file)

You will see the same behavior in a Finder or System Events tell statement. The solution is the same for ASObjC - you need to use it as a coercion:

set jsHFSFile to (theJSPath as POSIX file)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文