One liner that works in Applescript but not in ApplescriptObjC?

This one liner works fine in the Applescript Editor:


        tell application "Finder" to open POSIX file "/Development/Applescript/Rapport.docx"

However, it doesn’t when inserted in a newly created (with Xcode 5.1.1 under Mac OS X Mavericks 10.9.2) ApplescriptObjC project:


	on applicationWillFinishLaunching:aNotification
	    -- Insert code here to initialize your application before any files are opened
            tell application "Finder" to open POSIX file "/Development/Applescript/Rapport.docx"
	end applicationWillFinishLaunching:

I get the following error message:

I am an experienced Cocoa developer, but an Applescript newbie.

What did I miss?

Thanks a million

Hi,

in AppleScriptObjC you have to write

tell application "Finder" to open "/Development/Applescript/Rapport.docx" as POSIX file

Then why not the Cocoa way ?


current application's NSWorkspace's sharedWorkspace()'s openFile:"/Development/Applescript/Rapport.docx"

Thanks for the solution. Are there many gotchas such as that one? Are the differences documented somewhere?

The reason for doing it in Applescript is: I want to learn it!

Any fast track reading recommendation?

Now the example I gave is a reduction of a larger problem. Hopefully, your solution will help for that one as well. If not, I’ll followup.

Thanks again.

Jean-Denis

Apple’s documentation is quite poor, the best reference is Shane Stanley’s book AppleScriptObjC Explored

There are a few similar: you can’t use terms like file, alias and date as specifiers, but rather you have to use them as coercions.

These apply only when using ASObjC in Xcode projects – not in ASObjC-based libraries.

(The reason is because specifiers always need a parent specifier, and the parent of an ASObjC class is is a Cocoa class, not AppleScript, and hence the specifier can’t be resolved.)