Created
June 15, 2026 14:06
-
-
Save agentcooper/d667e09e258b72557bed942823f8d861 to your computer and use it in GitHub Desktop.
Bulk change default app on macOS for code file extensions
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
| swift - <<'EOF' | |
| import AppKit | |
| import UniformTypeIdentifiers | |
| let bundle = "com.microsoft.VSCode" | |
| let exts = ["c","h","rs","go","ts","js","json","yaml","toml","md","sh","py","swift","css"] | |
| for ext in exts { | |
| guard let uti = UTType(filenameExtension: ext)?.identifier else { continue } | |
| let before = LSCopyDefaultRoleHandlerForContentType(uti as CFString, .all)?.takeRetainedValue() ?? "none" as CFString | |
| LSSetDefaultRoleHandlerForContentType(uti as CFString, .all, bundle as CFString) | |
| let after = LSCopyDefaultRoleHandlerForContentType(uti as CFString, .all)?.takeRetainedValue() ?? "none" as CFString | |
| print(".\(ext.padding(toLength:8,withPad:" ",startingAt:0)) \(before) -> \(after)") | |
| } | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment