Visual Studio Code is a powerful code editor, but sometimes you need to open files with their default applications. This guide shows you how to configure VS Code to open files with their associated programs on both macOS and Windows.
Prerequisites
Before you begin, ensure you have:
- Visual Studio Code installed
- Basic understanding of VS Code’s command palette
- Appropriate file associations set up on your operating system
Configuring File Opening Tasks
For macOS Users
- Open the Command Palette (CMD + Shift + P)
- Type “Tasks: Configure Task” and select it
- Add the following JSON configuration:
{
"version": "2.0.0",
"tasks": [
{
"label": "Open file",
"type": "shell",
"command": "open",
"args": ["${file}"]
}
]
}
For Windows Users
- Open the Command Palette (Ctrl + Shift + P or F1)
- Type “Tasks: Configure Task” and select it
- Add the following JSON configuration:
{
"version": "2.0.0",
"tasks": [
{
"label": "Open file",
"type": "shell",
"command": "explorer.exe",
"args": ["${file}"]
}
]
}
Using the Task
After configuring the task:
- Open the file you want to view in its default application
- Open the Command Palette
- Type “Tasks: Run Task”
- Select “Open file”
Common Use Cases
- Opening HTML files in your default browser
- Viewing images in your system’s image viewer
- Opening PDFs in your PDF reader
- Playing media files in your media player
Troubleshooting
If the task doesn’t work as expected:
- Verify the file associations in your operating system
- Check if the file path contains spaces (they should work, but verify)
- Ensure you have the necessary permissions to open the file