Skip to content

Commit 4a8a77c

Browse files
author
John Elm
committed
Merge remote-tracking branch 'origin/master'
2 parents 1696e42 + a59cc5d commit 4a8a77c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ const myModule = require( './my-module' ); // local modules too
3131
> ES6 module syntax (`import from`) isn't currently supported, so stick with `require()`, and use `module.exports` in your own local modules.
3232
3333
You can also use your **favorite Javascript editor** instead of the OS X Script Editor, and use workflow that is much more familiar to JS developers (vs. compiling .js files to .scpt binary format).
34+
35+
So long as your editor can launch a shebang'd script, you can run or debug JXA while you edit.
3436

3537
## Installation and usage
3638

3739
You'll likely want to install node-jxa globally:
3840
```bash
39-
yarn global add node-jxa # or the npm equivalent
41+
yarn global add node-jxa # or the npm equivalent: npm install -g node-jxa
4042
```
4143

4244
This will install `node-jxa` and make it available in your `PATH` env var.
@@ -81,6 +83,9 @@ All modules you `require` in your scripts must be installed (i.e. in the `node_m
8183

8284
I suggest managing your node-jxa scripts like any node.js project, with a package.json specifying the needed module dependencies. Simply use `yarn` or `npm` to add and remove the libraries you need.
8385

86+
> Note that Browserify won't automatically package modules for which the `require`d path is computed at runtime. For example, `let myNeededModulePath = './my/needed/module' ; let myModule = require( myNeededModulePath );` will leave the module out and it won't work. This can happen within modules you're getting from npm.
87+
> Browserify has techniques for handling this, but node-jxa doesn't currently employ them.
88+
8489
### Using Applescript libraries
8590

8691
You can use your Applescript libraries in your JXA scripts using the `Library` global function, like so:
@@ -99,19 +104,19 @@ This works with JXA libraries too - you can use `Library()` to import .scpt scri
99104
100105
### Scripting Dictionaries
101106

102-
With node-jxa you can use your favorite JS editor for writing and managing your JXA code, but the OS X Script is still useful for viewing the Scripting Dictionaries for your scriptable apps. Essentially, this is the documentation for the API exposed by the apps' developers. Look for **Open Dictionary...** on the File Menu.
107+
With node-jxa you can use your favorite JS editor for writing and managing your JXA code, but the OS X Script is still useful for viewing the Scripting Dictionaries for your scriptable apps. Essentially, this is the documentation for the API exposed by the apps' developers. Look for **Open Dictionary...** on the File Menu, and be sure to select `JavaScript` in the language selector at the top.
103108

104109
### Be prepared for some weirdness
105110

106111
Some things are weird, including but not limited to:
107112

108113
- trying to `console.log` a JXA application object will probably crash the process.
109-
- arrays returned directly by Applications (i.e. searching or filtering) are weird. A simple trick like `array.map( el => el )` will give you a real JS array.
114+
- [Element Arrays](https://developer.apple.com/library/content/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW9) (arrays provided directly by Applications ( or [filtering via `whose()`](https://developer.apple.com/library/content/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-10.html#//apple_ref/doc/uid/TP40014508-CH109-SW10) ) are weird. A simple trick like `array.map( el => el )` will give you a real JS array.
110115
- property access for JXA objects is expensive. If you're doing many reads, your script can take a long time and may even time out. A caching strategy can help.
111116

112117
### Debugging
113118

114-
You can [debug your JXA scripts](https://developer.apple.com/library/content/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-11.html#//apple_ref/doc/uid/TP40014508-CH110-SW3) using Safari dev tools.
119+
You can debug your JXA scripts using Safari dev tools. To debug, [enable JSContexts support](https://developer.apple.com/library/content/releasenotes/InterapplicationCommunication/RN-JavaScriptForAutomation/Articles/OSX10-11.html#//apple_ref/doc/uid/TP40014508-CH110-SW3) in Safari, then simply include the `debugger;` command in your script. When you run the script it'll stop and open at that spot in the Safari debugger (from here, you can add additional breakpoints in Safari's debugger).
115120

116121
If you add the `--debug` (or `-d`) switch to the `node-jxa`, command (including in your shebangs), Browserify will include sourcemaps in the bundled code, for a cleaner debugging experience that is more focused on your own code.
117122

0 commit comments

Comments
 (0)