johnelm / node-jxa Goto Github PK
View Code? Open in Web Editor NEWUse your favorite node.js modules (and JS editor) for your Javascript OSX automation scripts
Use your favorite node.js modules (and JS editor) for your Javascript OSX automation scripts
.. thought maybe not since there's only a couple. But it'll clean this up a bit.
some ideas here, e.g. webpack etc: JXA-Cookbook/JXA-Cookbook#24
what ide I should use to run and play around with example.js?
what do I need to set up?
First, let me express my tremendous gratitude to John for providing this excellent library/resource.
I look forward to using it.
Now to my question:
It is great that this extension provides us with the ability to code, compile, and run JXA files:
AppleScript & JXA for Visual Studio Code
Unfortunately, JavaScript code completion is not active for a JXA file, even though JXA uses core JavaScript. Is there some way to enable it for JXA?
I am brand new to VSC, so if you can, please provide detailed instructions.
I realize this is NOT directly related to this repository, but I'm hoping the expertise is here that can answer this question. I've asked elsewhere without finding a solution.
Thanks.
I get an error in VSC using Code Runner with this script:
#!/usr/bin/env osascript -l JavaScript
var app = Application.currentApplication();
app.includeStandardAdditions = true;
console.log("Test Get app name");
var appProp = app.properties(); // <== fails on this line
appProp.name;
/*
ERROR MSG:
117:148: execution error: Error on line 6: Error: Message not understood. (-1708)
NOTE: Even though it says "line 6", the actual line is 7, as line 6 outputs correctly.
For completeness here's the entire Code Runner output:
[Running] /usr/bin/env osascript -l JavaScript "/Users/Shared/Dropbox/SW/DEV/JXA/VSC/Test Using CodeRunner Ext.js"
Test Get app name
/Users/Shared/Dropbox/SW/DEV/JXA/VSC/Test Using CodeRunner Ext.js:117:148: execution error: Error on line 6: Error: Message not understood. (-1708)
[Done] exited with code=1 in 0.11 seconds
*/
This same script, without the shebang, runs fine in Script Editor.
What am I doing wrong in VSC?
Is that possible to integrate node-jxa to node, instead of node to node-jxa?
Then you can use it in Electron?
.. ES6 module isn't supported, not aren't.
Should introduce node-debug-jxa
along with the node-jxa
command.
.. includes a dump of the stream meta:
{ Error: Cannot find module '/Users/jelm1/code/node-jxa/blah' from '/Users/jelm1/code/node-jxa'
at /Users/jelm1/.config/yarn/global/node_modules/browser-resolve/node_modules/resolve/lib/async.js:55:21
at load (/Users/jelm1/.config/yarn/global/node_modules/browser-resolve/node_modules/resolve/lib/async.js:69:43)
at onex (/Users/jelm1/.config/yarn/global/node_modules/browser-resolve/node_modules/resolve/lib/async.js:92:31)
at /Users/jelm1/.config/yarn/global/node_modules/browser-resolve/node_modules/resolve/lib/async.js:22:47
at FSReqWrap.oncomplete (fs.js:152:21)
stream:
Labeled {
_readableState:
ReadableState {
objectMode: true,
highWaterMark: 16,
buffer: BufferList { length: 0 },
length: 0,
pipes: [Object],
pipesCount: 1,
flowing: true,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events:
{ end: [Array],
error: [Function],
data: [Function: ondata],
_mutate: [Object] },
_eventsCount: 4,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: true,
highWaterMark: 16,
finalCalled: false,
needDrain: false,
ending: true,
ended: true,
finished: true,
destroyed: false,
decodeStrings: true,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: false,
bufferProcessing: false,
onwrite: [Function],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: true,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: [Object] },
writable: false,
allowHalfOpen: true,
_options: { objectMode: true },
_wrapOptions: { objectMode: true },
_streams: [ [Object] ],
length: 1,
label: 'deps' } }
currently node-jxa will exit with a status of 0, even if something goes wrong.
Hi John,
It seems that node-jxa uses browserify to generate a single script file each time it is invoked. For scripts that are called often, or that are substantial in size, this is quite a bit of overhead.
So I was wondering whether the node-jxa command could accept an option that changes its behaviour to instead generate a .scpt file using osacompile
command. This .scpt file can then be used and shared as like any other applescript, but also isn't regenerated on each invocation.
Perhaps a -c
option which takes a file path for the resulting compiled .scpt file.
I hope this makes sense?
Is this something you would consider adding to this great tool?
Many thanks.
Damo.
I am building an electron app and I am getting the following error in my console when I call var nodejxa = require('node-jxa')
from my JavaScript:
/Users/Me/Documents/git/electronHelloWorld/node_modules/node-jxa/node-jxa.js:15 Error: Can't walk dependency graph: Cannot find module '/Users/Me/Documents/git/electronHelloWorld/--field-trial-handle=1718379636,12704840948703548028,9979737565501458108,131072' from '/Users/Me/Documents/git/electronHelloWorld/_fake.js'
required by /Users/Me/Documents/git/electronHelloWorld/_fake.js
at /Users/Me/Documents/git/electronHelloWorld/node_modules/resolve/lib/async.js:137
at load (/Users/Me/Documents/git/electronHelloWorld/node_modules/resolve/lib/async.js:156)
at onex (/Users/Me/Documents/git/electronHelloWorld/node_modules/resolve/lib/async.js:181)
at /Users/Me/Documents/git/electronHelloWorld/node_modules/resolve/lib/async.js:15
at FSReqCallback.oncomplete (fs.js:172)
Hi. If you install the current (2.1.2) release from NPM, you'll get an error when Node-jxa runs osacompile
:
osacompile: couldn't write to file /Users/john/code/node-jxa/deleteme.scpt: No such file or directory
The vars at the top of node-jxa.js
look like this in that release:
const HEAD = 'window = this;\nObjC.import("stdlib");\ntry {\n ';
const TAIL = ';\n} catch (e) {\n console.log( e.message );\n $.exit(1); \n}\n$.exit(0);';
const OSA_JXA_CMD = 'osacompile';
const OSA_JXA_CMD_ARGS = ['-l', 'JavaScript', '-o', '/Users/john/code/node-jxa/deleteme.scpt' ];
You can check code in NPM's module package by getting the archive address with npm view node-jxa dist.tarball
and downloading the archive.
My guess is you might want to republish the release if NPM allows that, because code for the release seems to be different here on Github.
require
ing is derived at runtimeA declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.