-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with the JXA Application.currentApplication() Object #27
Comments
To provide more info, VSC with Code Runner seems to work fine otherwise using the #!/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) |
hey @JMichaelTX , I think what's happening there is that 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 #!/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 |
@johnelm , thanks for the quick response. And now I have been able to install your node-jxa, so this works: |
@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: but returns "undefined" for:
Not a big deal. I very rarely use the properties of the currentApp, so I don't see an issue here. |
Hmm, interesting. When I ran the script from within vscode, I’ve actually never used Cheers, 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. |
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. |
I get an error in VSC using Code Runner with this script:
This same script, without the shebang, runs fine in Script Editor.
What am I doing wrong in VSC?
The text was updated successfully, but these errors were encountered: