Comments (6)
hey @JMichaelTX ,
I think what's happening there is that Application.currentApplication()
is returning an Application object when you run it from within vscode (and thus vscode is the active app), even though vscode is not an OSA scriptable app.
This is interesting.. it looks like the app object obtained for a non-scriptable app is still a valid object. It has a working id() and name(). And it can be decorated with Standard Additions like any other app object, so methods like displayDialog()
will work. But it has no properties()
etc.
#!/usr/bin/env osascript -l JavaScript
let app = Application.currentApplication();
// or
app = Application( "/Applications/Visual Studio Code.app" );
app.includeStandardAdditions = true; // app.displayDialog and so forth will work
// const props = app.properties(); // doesn't work
console.log( `app.name(): "${app.name()}"`) // "Visual Studio Code"
console.log( `app.id(): "${app.id()}"`) // "com.microsoft.VSCode"
On the other hand, Script Editor is a scriptable app, and so it provides properties()
and other app-scripting goodies.
from node-jxa.
I think what's happening there is that Application.currentApplication() is returning an Application object when you run it from within vscode (and thus vscode is the active app), even though vscode is not an OSA scriptable app.
@johnelm, Thanks for your very quick replies and help.
one minor glitch. Your script:
console.log( `app.name(): "${app.name()}"`) // "Visual Studio Code"
console.log( `app.id(): "${app.id()}"`) // "com.microsoft.VSCode"
works for:
app = Application( "/Applications/Visual Studio Code.app" );
but returns "undefined" for:
let app = Application.currentApplication();
app.name(): "undefined"
app.id(): "undefined"
Not a big deal. I very rarely use the properties of the currentApp, so I don't see an issue here.
from node-jxa.
To provide more info, VSC with Code Runner seems to work fine otherwise using the currentApplication()
object:
#!/usr/bin/env osascript -l JavaScript
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var msgStr = "Test using VSC Code Runner"
var titleStr = "Test Using CodeRunner"
app.beep()
var oAns = app.displayDialog(msgStr,
{
withTitle: titleStr
,withIcon: "caution"
,buttons: ["Cancel","OK"]
,defaultButton: "OK"
,cancelButton: "Cancel"
})
var ansStr = oAns.textReturned
var btnStr = oAns.buttonReturned
console.log("Btn: " + btnStr)
from node-jxa.
@johnelm , thanks for the quick response.
OK that solves my issue.
And now I have been able to install your node-jxa, so this works:
from node-jxa.
Hmm, interesting. When I ran the script from within vscode, Application.currentApplication()
returned the same app object as when I specified it explicitly.
I’ve actually never used Application.currentApplication()
; I’ve always been able to target a specific scriptable app in my scripts.
Cheers,
John
PS: you’re a committer for the JXA-Cookbook, yeah? Can anyone make edits, or do you accept PRs on the wiki repo? I was thinking of suggesting node-jxa links in the couple spots where the browserify trick is suggested.
from node-jxa.
hey @JMichaelTX
I'll close these issues in a bit.
You’re a committer for the JXA-Cookbook, yeah? Can anyone make edits, or do you accept PRs on the wiki repo? I was thinking of suggesting node-jxa links in a couple spots where the browserify trick is suggested, in the Cookbook. Let me know what you think.
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
- 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
- Feature Request - Add commandline option to generate compiled .scpt file from source HOT 2
- 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.