You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Visual Studio Code中为JXA文件启用JavaScript代码补全(Intellisense)?

Enable JavaScript Autocompletion for JXA Files in VS Code

Great question—this is a common pain point with JXA in VS Code, but there are two key steps to get proper JavaScript intellisense working. Let's walk through them step by step, since you're new to VS Code:

Step 1: Associate JXA File Extensions with JavaScript Language Mode

VS Code might not automatically recognize .jxa or .scpt (JXA) files as JavaScript, which is why autocompletion isn't triggering. Here's how to fix that:

  • Open any JXA file in VS Code.
  • Look at the bottom-right corner of the window—you'll see a label like "AppleScript" (the current language mode). Click on it.
  • In the dropdown menu that appears, select Configure File Association for '.jxa'... (replace .jxa with whatever extension your JXA files use).
  • Choose JavaScript from the list. Now all files with that extension will be treated as JavaScript, enabling basic JS autocompletion.

Step 2: Add JXA-Specific Type Definitions

JXA has unique APIs (like Application, Path, etc.) that aren't part of standard JavaScript, so we need to install type definitions to get autocompletion for those. Here's how:

  1. Install Node.js (if you don't have it already)—it includes the npm package manager needed for the next step.
  2. Open the VS Code Terminal: Go to View > Terminal (or press Ctrl+`` on Windows/Linux, Cmd+`` on Mac).
  3. Install the JXA type definitions: Run this command in the terminal:
    npm install --save-dev @types/jxa
    
  4. Create a jsconfig.json file: In the root folder of your JXA project, create a file named jsconfig.json with the following content:
    {
      "compilerOptions": {
        "types": ["jxa"]
      },
      "include": ["**/*.jxa", "**/*.scpt"]
    }
    
    This tells VS Code to load the JXA type definitions for all your JXA files, so autocompletion will work for JXA-specific objects and methods.

Verify It Works

After completing these steps, open a JXA file and try typing Application(—you should see autocompletion suggestions for JXA's Application class, along with parameter hints and documentation. If something doesn't work, restart VS Code to ensure the changes take effect.

Note: A small number of niche JXA APIs might not be covered by the type definitions, but this setup will handle the vast majority of common use cases.

内容的提问来源于stack exchange,提问作者JMichaelTX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:50:20