JXA: How to Install the JXApp?

###How do I install the JXApp on my machine so I can use the standard JavaScript functions alert(), prompt(), confirm(), and other libraries?

I have read the below page, and the linked pages at JXA Cookbook, about 3 times now. They refer to each other in a never-ending circle.

Access JXA App Instance and shims for alert, prompt and confirm

This page send me to:
this recipe on JavaScript for Automation Cookbook

which sends me to:
Importing Scripts

which is a very confusing page referring to lots of stuff.

At this point, my head is spinning. :dizzy_face:

Maybe I’m just stupid, but I really have read all of this stuff at least 3 times, and it’s not clear where to start, and exactly what steps are needed.

I need clear, step-by-step instructions, not just for me, but for other users (who are not JXA coders) that I will send my JXA scripts to. There is no way a non-tech, non-programmer user could understand what to do.

Ultimately, I would like to include other libraries in my JXA scripts, like JQuery and JQuery UI. But I need setup instructions for the end user.

Can anyone help?

TIA.

Are you sure you want JXApp ? it's just a Node.js library that someone has written – not a standard or essential part of using JavaScript for Applications, and not an OSX.app

It's essentially a way of getting a reference to an instance of JavaScript for Application's Application() object from inside Node.js code.

From Script Editor you get a direct reference anyway with lines like:

var a = Application.currentApplication;
var appSafari = Application("Safari").

If for some reason you do want to write and run Node.js code, and call Node.js modules, you will first need to install Node.js

Once you have done that, you will be able to use npm install <NodeJS_ModuleName> from a Bash prompt in Terminal.app

Perhaps that is really what you want to do ? Your reference to 'the' JXApp makes me wonder whether a confusion has perhaps arisen – that page of the CookBook probably does assume a Node.js-using audience, and could be a bit opaque to more general readers.

Also, it looks as if there's a dangling link there, following an edit to the CookBook wiki – the link from the npm module page should really be to the discussion of exotic interactions and library-calling gymnastics here:

Well, remember that JQuery is a web engine library – it presents a richer and browser-independent interface to the web page DOM.

JavaScript for Applications doesn't itself include a browser or anything that JQuery could go to work on (though you can, of course script Safari or Chrome) – but perhaps you are thinking of hybrid web + OS X automation applications ?

No, I'm not. :smile:

Thanks for responding, Rob.

Here's what I want to accomplish. Perhaps you can suggest the best approach to do so.

  1. Be able use use the std JavaScript UI functions described above, without have an object prefix.
    - IOW, use alert() directly without having to use someLib.alert()
    - I'm reading a JavaScript book with lots of examples I'd like to just copy/paste into the Script Editor as is.
  2. Ultimately I would like to use the JQuery UI lib for stuff like the autocomplete() functions.
  3. I'm also anticipating that there are other JS libs, like JQuery, that I might like to use in the future
  4. I'm not exactly sure what the "jxapp" is, but somewhere I thought I read that it would provide access to a lot of other useful functions. But I can't seem to find that page now. :frowning:

Bottom line: I want to take max advantage of JavaScript libraries already built when using JXA.

Any guidance is greatly appreciated.

TIA.

Yes, exactly. I have a number of ideas for automating Evernote (the EN Mac app) that involve:

  1. Highly customized web clipping (beyond what the EN Clippers does now).
  2. Offering the user (including me), the cool autosuggest/autocomlete of Notebooks and Tags that is in the EN Web clipper (no API is provided for this).
  3. Building some nice HTML forms for the above tasks

Also, I have an extensive JavaScript library from yesteryear that I may want to use. A lot of has nothing to do with HTML or the web. They are just generic JavaScript functions. OTOH, libs like JQuery may have better implementations of these functions, and a lot more.

Thanks.

Rob, here are some statements on the JXA Cookbook that intrigue me:

From this page: Importing Scripts

Imagine that we can use JavaScript libraries likes Lo-Dash in JavaScript for Automation using a simple require call! It's now possible, thanks to browserify.

Using Browserify, you can bundle a Node.js script with all their dependencies to run on a JXA environment.

One benefit of this approach is that the resulting script is portable, because all dependencies are bundled up inside a single JavaScript file.

Let's Do It

npm is a place to host any JavaScript package, not just Node packages. Imagine that JXA-specific modules are available on npm... You'd be able to require a library to use the file system without having to deal with all the Objective-C complexities

OK, Browserify may well be what you want then : - )