Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Cannot Understand Event Earsffdr Cocoa-Applescript

Hello Guys,

I'm trying to just write a little X-code 4 app to display it's own directory, using Cocoa-Applescript. I've created a window under MainMenu.xib, and linked it to my code in AppDelegate.applescript. My code looks something like this:


on myButtonHandler_(sender)

set theFolder to POSIX path of (the path to current application)

set theFile to theFolder & "/Contents/Resources/Dir.app"

display dialog (the path to me)

return void

end myButtonHandler



The app builds perfectly, but when I click the button, it says:



[AppDelegate myButtonHandler:]: «script» doesn’t understand the «event earsffdr» message. (error -1708)


I have no idea what is happening there, so any help is appreciated!


P.S This code also works perfectly in Applescript Editor, but I want it to look better with a window, so this is really weird.

MacBook Pro, OS X Mountain Lion

Posted on Jan 29, 2013 4:23 PM

Reply
Question marked as Best reply

Posted on Jan 29, 2013 5:30 PM

Your example doesn't work for me in the AppleScript Editor either (without coercing the alias to text for the dialog), but you can't use the term path to me in a Cocoa-AppleScript. The path to current application does seem to work OK, but you can also get the path to the application bundle with NSBundle, e.g. current application's NSBundle's mainBundle()'s bundlePath(). In addition, the variable void is undefined (there is no void constant in AppleScript).

4 replies
Question marked as Best reply

Jan 29, 2013 5:30 PM in response to The CC

Your example doesn't work for me in the AppleScript Editor either (without coercing the alias to text for the dialog), but you can't use the term path to me in a Cocoa-AppleScript. The path to current application does seem to work OK, but you can also get the path to the application bundle with NSBundle, e.g. current application's NSBundle's mainBundle()'s bundlePath(). In addition, the variable void is undefined (there is no void constant in AppleScript).

Jan 29, 2013 9:36 PM in response to red_menace

I've tried the applecation bundle thing, and my code looks like this:



on myButtonHandler_(sender)

set theFolder to POSIX path of (the path to current application's NSBundle's mainBundle()'s bundlePath())

set theFile to theFolder & "/Contents/Resources/Dir.app"

display dialog theFile

end myButtonHandler



But now the error is:

«class ocid» id «data optr00000000E0B3660401000000» doesn’t understand the «event earsffdr» message. (error -1708)


In Applescript Editor, the code makes the error : NSBundle doesn’t understand the mainBundle message.

In addition, 'path to current application' doesen't work either, and it displays the original error.

Jan 30, 2013 7:20 AM in response to The CC

To use the NSBundle class (see the AppleScriptObjC Release Notes for conversion examples from Objective-C), your statements would be something like:


set theFolder to current application's NSBundle's mainBundle()'s bundlePath() as text

display dialog theFolder


Even though you can edit the scripts in ithe AppleScript Editor, it doesn't really know anything about the Cocoa frameworks - the various class definitions are provided by the template's runtime wrapper. Your application will need to be run by itself (errors and log statements are sent to the console), or you can use a third party editor such as the AppleScriptObjC Explorer.


Note that anything returned by a Cocoa method will be a Cocoa object, so when you see an error using something like «class ocid» id «data optr00000000E0B3660401000000», you are usually trying to use a Cocoa object without coercing it to an AppleScript class (in this case, an NSString to text).

Cannot Understand Event Earsffdr Cocoa-Applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.