“POSIX 文件"适用于 Applescript 编辑器,而不适用于 XCode [英] "POSIX file" works in Applescript Editor, not in XCode
问题描述
试试这个:
创建一个新的 XCode4 Applescript 项目.在委托中,粘贴以下代码:
on doIt_(sender)将 goodHFSLoc 设置为(桌面文件夹的路径)将 test1 设置为(goodHFSLoc 的 POSIX 路径)记录test1:"&test1将 JSPath 设置为/Users/dave/Desktop/MakeTSLabels.js"将 jsHFSFile 设置为(POSIX 文件 theJSPath)将 test2 设置为(jsHFSFile 的 POSIX 路径)结束做它_
将此方法与 UI 窗口中的按钮挂钩.
- 运行程序
点击按钮,你应该得到这个错误:
无法获取类NSObject"的POSIX路径.
- 将相同的代码(减去on"和end"行)放入 AppleScript 编辑器,它运行良好.
显然,ApplescriptObjC 中的POSIX 文件"没有将文件对象作为语言规范需要.相反,它生成了一个 NSObject.
我需要有一个 applescript 文件说明符来提供给 Adobe Illustrator 的 do javascript
命令,并且我需要使用 NSBundle 的函数来获取 javascript 文件,该文件打包在我的应用程序包中.>
我做错了吗?
您将在 Finder 或 System Events tell 语句中看到相同的行为.ASObjC 的解决方案是一样的——你需要将它用作强制:
set jsHFSFile to (theJSPath as POSIX file)
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?
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)
这篇关于“POSIX 文件"适用于 Applescript 编辑器,而不适用于 XCode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!