AppleScript under 10.7 Lion

Hello everyone,

first, I am a beginner with apple and mac os.

I have wrote a script for 10.6 to use the spellchecker within my Java-Program:

tell application "Automator Runner"

   set mySpellChecker to call method "sharedSpellChecker" of class "NSSpellChecker"

   set foundLanguages to call method "availableLanguages" of mySpellChecker

end tell

which works nice under 10.6

But now under 10.7 even under the applescript console an error occurs at:


tell application "Automator Runner"

   set mySpellChecker to call [b]method[/b] "sharedSpellChecker" of class "NSSpellChecker"

   set foundWords to call method "availableLanguages" of mySpellChecker

end tell

Expected end of line but found identifier.

Can anyone please give me a hint, what has changed from 10.6 to 10.7. In the Changelog I cant find either an AppleScript change or a change with the spellchecker API. Also other scripts from the web using the “to call method …” fails with the same error.

Thanks for any reply in advice

Michael Coldewey

Browser: Firefox 7.0.1
Operating System: Mac OS X (10.7)

I might be mistaken, but i think the call method method has been deprecated in Lion. Mainly because you can now use AppleScriptObjectiveC within the AppleScript Editor.

I successfully made it work like this:

First I created a new Cocoa-AppleScript Applet byt going to the File menu, New from Template, Cocoa-AppleScript Applet. Saved it on the desktop for now, then I integrated this code:

set spellChecker to current application's NSSpellChecker's sharedSpellChecker()
set foundLanguages to spellChecker's availableLanguages()

But the thing is, this returns an NSArray object, and i’m not quite sure how to do that within AppleScript. Tried to coerce it to list, but it didn’t work.

What happens in the script is I first create an instance of the sharedSpellChecker (just like your first line did before), and then applied the instance method availableLanguages on the sharedSpellChecker instance to receive an array from it (like your second line did before). Same result, but different way of calling it. In ObjC it would look like this:

NSArray* foundLanguages = [[NSSpellChecker sharedSpellChecker] availableLanguages];

Also, in order to make this work, you need to launch the application. Just running the script won’t work, it will give you errors. You can find more info here:

http://macosxautomation.com/lion/applescript.html

I believe it would be more practical for you to switch to AppleScriptObjC within Xcode. Or use Shane Stanley’s AppleScriptObjC Explorer app:

http://www.macosxautomation.com/applescript/apps/explorer.html

Good luck!

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)

Hi and Thx for your reply.

I tried your solution before but did not notice, that i have to run it as cocoa applet.

I dont know how to do this in a JAVA call, but i will find out. Java executes only plain scripts but no cocoa applets.

Why did they remove the “call method” mechanic? There must be a replacement in regular scripts, i think.

Best regards
Michael Coldewey

I have seen a few posts on the web just now, it seems that the call method method has been removed from Lion. As to why, I strongly believe it is due to the addition of ASOC to the AppleScript Editor, which does this and tons more. Call method was a very limited, very simple way to access ObjC methods.

Model: MacBookPro8,2
Browser: Safari 534.51.22
Operating System: Mac OS X (10.7)