问题
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?
回答1:
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)
来源:https://stackoverflow.com/questions/9238480/posix-file-works-in-applescript-editor-not-in-xcode