" POSIX文件"工作在AppleScript的编辑器,而不是在X $ C $Ç [英] "POSIX file" works in Applescript Editor, not in XCode
问题描述
试试这个:
-
请新的X code4的AppleScript项目。在代表中,粘贴此code:
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_
挂钩这种方法最多UI窗口的按钮。
Hook this method up to a button in the UI window.
点击该按钮,你应该得到这个错误:
Click the button, and you should get this error:
Can’t get POSIX path of class "NSObject".
显然,ApplescriptObjCPOSIX文件不会使一个文件对象的语言规范<一个href=\"https://developer.apple.com/library/mac/documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_classes.html#//apple_ref/doc/uid/TP40000983-CH1g-SW15\"相对=nofollow>要求。相反,它使一个NSObject的。
Apparently, "POSIX file" in ApplescriptObjC doesn't make a file object as the language specification requires. Instead it makes an NSObject.
我需要有一个AppleScript文件说明,以提供Adobe Illustrator中的做的JavaScript
命令,我需要使用一个NSBundle的函数来获得的JavaScript文件,该文件打包在我的应用程序包。
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.
我是不是做错了什么?
推荐答案
您将看到在搜索或系统事件相同的行为告诉声明。该解决方案是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:
set jsHFSFile to (theJSPath as POSIX file)
这篇关于&QUOT; POSIX文件&QUOT;工作在AppleScript的编辑器,而不是在X $ C $Ç的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!