How to set default open program for .js file

I’ve asked gpt, but the output code always has syntax error… like this

set default_handler for '.js' to 'vscode'

how to fix it

To know how with Chat GPT, you’d better to use specific technical words.

I wrote “How to register a new application for a specific file name extension for example “js” on macOS using lsregister command?”.

Chat GPT returned…

To register a new application for a specific file name extension (e.g. “js”) on macOS using the lsregister command, follow these steps:

1 Open Terminal on your Mac by navigating to Applications > Utilities > Terminal.
2 Type the following command into the Terminal window and press Enter:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -f /path/to/application.app

Replace “/path/to/application.app” with the actual file path to your application’s .app file that you want to register.

  1. Once you’ve entered the command, press Enter to execute it. You should see a message in the Terminal indicating that the registration was successful.

Note: If you receive an error message when attempting to run the lsregister command, try running the command with superuser privileges by prefixing it with “sudo” and entering your administrator password when prompted.

How exactly can you use lsregister to cause VSCode to handle .js files?

As far as I’m aware lsregister is only used to register an app with launch services.

To actually register an app to manage various file types I believe a bit more is required:

At first, I write this clearly. I’m trying this and not success yet.

Make entry for js by default command and execute lsregister to refresh database, as I acknowledge.

do shell script "defaults write com.apple.LaunchServices LSHandlers -array-add \"<dict><key>LSHandlerContentTag</key><string>js</string><key>LSHandlerContentTagClass</key><string>public.filename-extension</string><key>LSHandlerRoleAll</key><string>com.apple.dt.Xcode</string></dict>\""

do shell script "/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user"
1 Like