Closed bpatram closed 6 years ago
Right now this is my makeshift VSCode config to run Javascript applescript scripts. This primarily shows that all we'd need to add is -l JavaScript
when calling osascript
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Script",
"type": "shell",
"command": "/usr/bin/osascript",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"args": [
"-l JavaScript",
"${workspaceFolder}/main.applescript"
],
"problemMatcher": []
}
]
}
I need to find a way to tell apart AppleScript from JavaScript (JXA), so I was hoping you could give me some insights. When you work on a a script, do you set the syntax to JavaScript, but save your files as *.applescript
?
It would probably be best to define a custom syntax scope for JXA, but you would have to pick the syntax for those files manually, since both AppleScript and JXA use the same file-extension (from what I can tell). The benefit of that is that I could preserve the functionality of the buttons in the top right.
@idleberg Personally, I keep the .applescript
file extension and set the document syntax to JavaScript. I haven't seen anything in Apple's documentation stating to use a different file extension for the JavaScript variant of Applescript.
We could create a new file extension instead, maybe .js.applescript
, or .applescript.js
. This may be a more ideal solution than sharing a file extension for two syntaxes.
Sharing the same file extension for two different languages may be cumbersome for users if it requires them to switch to the correct one (applescript vs javascript) each time they open the file. I'm not sure if VSCode has some built in functionality to guess a language based on file contents.
Unfortunately, things aren't that easy. When I create a new language syntax for JXA and assign the *.applescript
extension, there's a conflict with normal AppleScript files. I then thought of eval()
over an opened file (at least optionally, since it might be costly), but it seems the VSCode API has no method to manually override the language.
In the end, I followed the Atom package's example and made *.jxa
and *.jxainc
the default file extensions. Of course, you can keep using *.applescript
or *.js
, but you will have to override the language manually (maybe VSCode has a setting to remember your preference?)
That said, v0.10 now has support for JXA!
Seems that JavaScript has no auto-complete feature yet?
Support Javascript language for scripting. I think this would just be slight modifications to calling the compiler and runner processes and possibly adding "Javascript Applescript" as a new language?