“POSIX 文件”适用于 Applescript 编辑器,不适用于 XCode
试试这个:
创建一个新的 XCode4 Applescript 项目。在委托中,粘贴以下代码:
on doIt_(发件人) 将 goodHFSLoc 设置为(桌面文件夹的路径) 将 test1 设置为(goodHFSLoc 的 POSIX 路径) 记录“测试1:”和测试1 将 JSPath 设置为“/Users/dave/Desktop/MakeTSLabels.js” 将 jsHFSFile 设置为(POSIX 文件 theJSPath) 将 test2 设置为(jsHFSFile 的 POSIX 路径) 结束 doIt_
将此方法挂钩到 UI 窗口中的按钮。
- 运行程序
单击按钮,您应该收到此错误:
无法获取类“NSObject”的 POSIX 路径。
- 将相同的代码(减去“on”和“end”行)放入 AppleScript 编辑器中,它运行良好。
显然,ApplescriptObjC 中的“POSIX 文件”不会将文件对象作为语言规范需要。相反,它创建一个 NSObject。
我需要有一个 applescript 文件说明符来提供给 Adobe Illustrator 的 do javascript
命令,并且我需要使用 NSBundle 的函数来获取打包在我的应用程序包中的 javascript 文件。
我做错了什么吗?
Try this:
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_
Hook this method up to a button in the UI window.
- Run the program
Click the button, and you should get this error:
Can’t get POSIX path of class "NSObject".
- 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将在Finder或系统事件tell语句中看到相同的行为。 ASObjC 的解决方案是相同的 - 您需要将其用作强制:
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: