Skip to content

Instantly share code, notes, and snippets.

@tillig
Created January 23, 2024 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tillig/ec13119c41809c440449170e70f83bb6 to your computer and use it in GitHub Desktop.
Save tillig/ec13119c41809c440449170e70f83bb6 to your computer and use it in GitHub Desktop.
Script to set VSCode as the default editor for select file types on MacOS
$duti = Get-Command "duti" -ErrorAction SilentlyContinue
If ($Null -eq $duti) {
throw "You must install 'duti' before running this script: brew install duti"
}
$duti = $duti.Source
# $vscode = com.microsoft.VSCode
$vscode = osascript -e "id of app `"Visual Studio Code`""
# Dump info about extensions like:
# duti -e .md
# Not all extensions have a type identifier. You can still assign a default handler, though.
$extensions = @(
".config",
".cs",
".cshtml",
".csproj",
".go",
".hcl",
".js",
".json",
".log",
".proj",
".props",
".ps1",
".psd1",
".psm1",
".resx",
".rst",
".ruleset",
".scala",
".sh",
".sln",
".tf",
".tfstate",
".tfvars",
".ts",
".txt",
".vb",
".xml",
".yaml",
".yml"
)
$extensions | ForEach-Object {
$extension = $_
# Set VSCode as the default handler for the extension.
&$duti -s $vscode $extension all
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment