Created
January 23, 2024 20:19
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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