"JavaScript for Automation" with OO4

Hi,

Looking at this document : Javascript for Automation, you can now write Javascript code instead of AppleSript to automate things on your Mac. As far as I understand, it’s a matter of language bindings on underlying framework, and it should be transparent to applications. (If I’m wrong, correct me !)

I’m trying to rewrite this small (working) AppleScript code :

tell application "OmniOutliner"
	tell document 1
		set width of column 3 to 123
	end tell
end tell

The equivalent Javascript might be :

Application('OmniOutliner').document[0].column[2].width=123;

But it fails with error :

Error -1700: Can't convert types.

I tried with document[1].column[3] in case of fancy 1 based indexes, but of course, this is not the problem.

It should be noted that the following code :

console.log("width.set : "+app.document[0].column[2].width.set)

produces this output (and no error) :

/* width.set : function () {
    [native code]
} */

loosely suggesting that we might be close to have some setter being called (and showing at least that the app.document[0].column[2] stuff is understood, in some way).

I thought that turning off restrictive “strict” stuff such as :

app.strictPropertyScope = false;
app.strictCommandScope = false;
app.strictParameterType = false;

might help, but it doesn’t.

Do you have any ideas why it’s not working, and how it could/should be done ? Does anyone had any success trying to use Javascript instead of AppleScript with Omni apps ?

Best wishes,

Julien

(Running OS X 10.10 and OO 4.1.4)

It took a while to crack this, (I hadn’t tried JavaScript for automation before).

The solution is to access the arrays using the plural forms of the elements. So this should work:

Application('OmniOutliner').documents[0].columns[2].width=123;

Martin

Having used JavaScript for automation further it seems it is worth setting these flags:

app.strictPropertyScope = true
app.strictCommandScope = true

So that more errors get reported as early as possible.

Martin

The plural forms of the elements ? Ouch ! Thank’s a lot :)

This post was flagged by the community and is temporarily hidden.