Comments (2)
Hi Damo,
Sorry it's taken me so long to reply.
I've done some playing with this. To try it, I changed the command in line 8 in node-jxa.js from osascript
to osacompile
. Then I tested it like this (assuming node is installed):
./index.js example.js
It produces the resulting compiled script as a.scpt
(it uses this for the filename if you don't provide one).
I think it's reasonable to expect that the resulting .scpt file 'can then be used and shared as like any other applescript' (quoting from your request), but it actually can't. The resulting script can be executed, using the osascript
command:
osascript a.scpt
But it can't be used as a Script Library. If this is attempted, the resulting .scpt file crashes the osa process, and hard. If run from Script Editor, it (Script Editor) is killed too. It doesn't seem to like the use of the $.exit()
from ObjC.import("stdlib");
, which is needed by node-jxa to correctly set the exit code when errors occur.
Even if we were willing to forego the $.exit()
call, using the library from another script fails with this cryptic error (I tested by requiring lodash):
Untitled.scpt:37:65: execution error: Error on line 3: Error: No error. (0)
OTOH, creating libraries in JavaScript and using them by require
ing them as described in the README, is working great for me.
I know it seems inefficient to bundle dependencies into an in-memory script every time, but I've never encountered any performance pain from it. Have you (sincere question)?
In any case the main intents and benefits (IMO) of this library are:
- to be able to do scripting work in JavaScript, using more robust and familiar tools (than Script Editor) and workflows (vs. compiling to .scpt)
- use many of the libraries available in npm
- use your own .js files as libraries by simply
require
ing them - being able to run executable (
chmod +x
) scripts withoutosascript
.. so to be honest I haven't been inclined to add the compile feature. But I tried it anyway to check it out, and it's not doable, at least not without a lot of work. Hoping you'll understand.
Thanks much for the request! Cheers,
John
from node-jxa.
hi @johnelm
Thanks for such a considered response. I think I may not have expressed the intention of the request well. While I do highlight the overhead of browserify having to bundle the script before executing it on each invocation, my primary goal is in relation to distributing the scripts themselves.
To bundle/share using the framework you have with node-jxa, you have to share a collection of source files essentially. What I was looking for was a way to compile or otherwise bundle up a distribution to a single file that can be shared, and shared in a way that existing applescripts currently do (i.e. a compiled .scpt file).
The resulting script can be executed, using the osascript command:
So this was exactly what I was after. A compiled file that can be executed using osascript, or by other automation services built into macOS (i.e. drop the file into a predefined folder for a given app).
But it can't be used as a Script Library.
The framework under which you have built node-jxa allows libraries to be reused via the standard npm package management tools and ecosystem, so I wasn't proposing to distribute libraries using node-jxa. This would seem redundant, and as you explain, requiring them works well already. It is also a well-known method of writing with javascript. This makes node-jxa a great tool to bring those skilled developers into the macOS automation ecosystem. The only gap with node-jxa is distribution of the scripts themselves.
So all I was looking for was a way to distribute a complete built script much like people typically do now with compiled applescripts. You drop a single file into a predefined folder and the apple automation system picks it up and integrates it.
I hope this makes more sense than my original request comment. :)
So the results of your playing were exactly what I was asking for. :)
Cheers,
Damo.
from node-jxa.
Related Issues (20)
- remove node-debug-jxa, since the βdebug switch can be used in all the same ways
- show error on spurious args
- Add a headsup to README about filesystem limitations HOT 1
- add a tip to simply include `debugger` to debug script
- add this tut to resources (includes tip on JXA with Alfred)
- propose link to node-jxa at these cookbook spots
- research browserify alternatives to work around limitations (i.e. fs access)
- How Do I use Visual Studio Code (VSC) with JXA and Retain JavaScript Code Completion? HOT 4
- Issue with the JXA Application.currentApplication() Object HOT 6
- wrap entire script in a try/catch, and $.exit(1) on error
- add a test confirming that the added code is valid & doesn't cause errors
- move all limitations in the README to a dedicated section
- not clear how to use example.js HOT 2
- chmod +x the example script in git
- Add info on installing dependencies to README
- The 2.1.2 release on NPM includes a reference to a developer-local directory (and doesn't correspond to the Github tag) HOT 2
- dependency graph error
- First
- Can I import Node-Jxa and use JXA stuff in Node?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-jxa.