Giter Club home page Giter Club logo

Comments (4)

johnelm avatar johnelm commented on June 6, 2024 1

Hey @JMichaelTX,

No worries I love to discuss this stuff. πŸ‘

I'm guessing that it works properly when you force it to use a Javascript syntax in the language selector in the lower right.

I use the idleberg extension too, it's awesome. But I don't use it for JXA anymore - these days I just use it for Applescript. If I'm understanding it right, it's providing two things for JXA files ( recognized by .jxa, .jxainc, or .js extensions ):

  • a JXA language syntax ( for syntax coloring ) that is based on Javascript's ( and there is nothing more for it to add ).
  • a set of commands for running, compiling and bundling JXA scripts ( with toolbar button(s) )

You can get both of these, plus the missing JS language support, by treating your JXA scripts as regular Javascript:

  • name your jxa scripts with the .js extension ( not .jxa )
  • include a shebang at the top; one of:
    • #!/usr/bin/env node-jxa # (if you're using it)
    • #!/usr/bin/env osascript -l JavaScript
  • use the Code Runner extension to run your JXA scripts - it regards shebangs by default.

The Code Runner extension actually includes support for running AppleScript files (shebang would work too), but we still need the idleberg extension for AS syntax coloring.

from node-jxa.

JMichaelTX avatar JMichaelTX commented on June 6, 2024

@johnelm

You can get both of these, plus the missing JS language support, by treating your JXA scripts as regular Javascript:

Thanks, John. I really appreciate your help.
I have not been able to install your node-jxa yet (I need instructions using npm to install), but using:
#!/usr/bin/env osascript -l JavaScript
with Code Runner seems to work OK, except for access to the Application.currentApplication() object.
I'll post another issue to address that.

One question here: Is it possible to associate the ".jxa" extension with JavaScript in VSC? I'd like to continue using it to denote my JXA scripts (vs my pure JavaScripts)?

Many thanks.

from node-jxa.

johnelm avatar johnelm commented on June 6, 2024

hey @JMichaelTX..

node-jxa installation
Ah I see.. node-jxa has to be installed globally, maybe that's why it's not working.

I should have included the npm installation command in addition to the yarn version.. (done just now). The command using npm is :

npm install -g node-jxa  #  ( `-g` can also be `--global`)

adding jxa file association for javascript
Yep you can do this by adding this line to your settings.json (you probably want to use your user settings, not workspace settings):

"files.associations": { "*.jxa":"javascript" },

Correction.. see next comment
It's a bit unpredictable though, since the idleberg extension also contributes a .jxa association. I just tested it and recognized it as Javascript the first time, but as 'Javascript for Automation (JXA)' the second time. I hope there's a way to force it to choose the former but I don't know how at the moment.

from node-jxa.

johnelm avatar johnelm commented on June 6, 2024

Quick update here @JMichaelTX .. It looks like my "file.associations" line in my setting.json was deleted by the settings sync extension that I'm using.. so I put it back permanently.

With that bit in my config, it does select Javascript for .jxa files repeatably, even though I still have the idleberg extension installed. I'm editing my last post accordingly.

from node-jxa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.