johnelm / node-jxa

Use your favorite node.js modules (and JS editor) for your Javascript OSX automation scripts
74 stars 4 forks source link

not clear how to use example.js #32

Closed id347627 closed 5 years ago

id347627 commented 5 years ago

what ide I should use to run and play around with example.js? what do I need to set up?

johnelm commented 5 years ago

hi @id347627

what ide I should use to run and play around with example.js?

You can use any IDE you like to try the example. My fave is vscode (Visual Studio Code). As I mentioned in the README.

So long as your editor can launch a shebang'd script, you can run or debug JXA while you edit.

I do this in vscode using the Code Runner extension. Its code-runner.respectShebang config setting in vscode must be set to true (the default setting).

But, you don't have to use an IDE at all to run the script, and this is largely the 'raison d'être' for node-jxa.. to be able to run your JXA scripts, potentially using modules from NPM, from your terminal or from any script launcher that can start a shell script, e.g. FastScripts, Alfred, Automator, etc.

what do I need to set up?

Dependencies

You must also make sure the script's dependencies are installed and available to node-jxa, as mentioned in the Project structure and availability of node modules section of the README.

the example.js file

For the example.js file in a local clone of node-jxa, this is easiest by running yarn or npm install from your local clone's project dir.

real-world usage

For real-world usage, you can install the dependencies:

The logic for how node finds dependencies is detailed in the node.js docs here, in the few sections starting with 'Loading from node_modules Folders'.

johnelm commented 5 years ago

I just realized that the example.js script (in the git repo) doesn't have execute permissions; I've created an issue to update its permissions so it's not necessary to chmod it before trying it.

I'll make a note to add a bit more info on dependencies to the README too.