Question

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?

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top