code-editor-switch
Purpose
Use this skill to switch Finder/Open defaults for code, text, and config files to a new editor (for example Zed, VS Code, Cursor) using duti.
When to use
- Migrating from one editor to another on macOS.
- Standardizing file defaults for local repos and team machines.
- Fixing mismatched defaults for dotfiles and config files.
Non-negotiable rules
- Run this only on macOS.
- Prefer
duti over direct LaunchServices plist edits.
- Apply both generic UTIs and concrete extensions/names.
- Keep
public.data opt-in only (--apply-public-data).
- Verify with
duti -x after applying mappings.
Workflow
1) Preflight
- Ensure
duti exists:
command -v duti >/dev/null || brew install duti
- Resolve bundle identifier for target editor:
osascript -e 'id of app "Cursor"'
mdls -name kMDItemCFBundleIdentifier -raw "/Applications/Cursor.app"
2) Apply baseline mappings
- Run:
bash "scripts/switch-code-editor.sh" --editor "Cursor"
- This applies:
- Core UTIs (
public.text, public.plain-text, public.source-code, etc.)
- Baseline code/config extensions (
ts, tsx, js, json, yaml, sql, py, css, toml, mdx, etc.)
- No-extension names like
Dockerfile
3) Add project-driven coverage (preview first)
- Preview discovered tokens before applying (required):
bash "scripts/discover-project-editor-tokens.sh" "$HOME/Developer/fmd-labs/viral-app"
bash "scripts/discover-project-editor-tokens.sh" "$HOME/Developer/fmd-labs/viral-app" | sed -n '1,120p'
- Optional safety check for obvious artifact noise:
bash "scripts/discover-project-editor-tokens.sh" "$HOME/Developer/fmd-labs/viral-app" | rg '^(dep-|build-script-|bin$|a$|d$)'
- Only after preview/review, apply project scan:
bash "scripts/switch-code-editor.sh" --editor "Cursor" --project "$HOME/Developer/fmd-labs/viral-app"
- If preview output is noisy, narrow
--project to a cleaner subdirectory or expand excludes first.
4) Verify
- Check representative mappings:
duti -x ts
duti -x tsx
duti -x env
duti -x gitignore
duti -x Dockerfile
- If Finder still opens old handlers, log out/in to refresh LaunchServices behavior.
5) Optional aggressive mode
- Only if explicitly requested:
bash "scripts/switch-code-editor.sh" --editor "Cursor" --apply-public-data
- Warning: this can redirect many non-code files.
Known edge cases
.ts can resolve to a non-code UTI on some systems; extension mapping is required.
- Dotfiles like
.env.local are often matched by suffix (local) plus text UTIs.
- Some apps may reclaim specific extensions after updates/reinstalls.
Deliverables
When using this skill, always return:
- Target editor and resolved bundle ID.
- Exact script command used.
- Summary of UTI + token mappings applied.
- 3-5 verification checks (
duti -x ...).
Progressive disclosure
Load only what is needed:
references/coverage-from-viral-app.md for practical extension gaps.
references/sources.md for source links and version checkpoints.
scripts/discover-project-editor-tokens.sh for token discovery.
scripts/switch-code-editor.sh for the full apply workflow.
1---2name: code-editor-switch3description: Install and use duti on macOS to switch default code/text/config file handlers to a target editor, including project-driven extension discovery and verification.4---56# code-editor-switch78## Purpose910Use this skill to switch Finder/Open defaults for code, text, and config files to a new editor (for example Zed, VS Code, Cursor) using `duti`.1112## When to use1314- Migrating from one editor to another on macOS.15- Standardizing file defaults for local repos and team machines.16- Fixing mismatched defaults for dotfiles and config files.1718## Non-negotiable rules1920- Run this only on macOS.21- Prefer `duti` over direct LaunchServices plist edits.22- Apply both generic UTIs and concrete extensions/names.23- Keep `public.data` opt-in only (`--apply-public-data`).24- Verify with `duti -x` after applying mappings.2526## Workflow2728### 1) Preflight2930- Ensure `duti` exists:31 - `command -v duti >/dev/null || brew install duti`32- Resolve bundle identifier for target editor:33 - `osascript -e 'id of app "Cursor"'`34 - `mdls -name kMDItemCFBundleIdentifier -raw "/Applications/Cursor.app"`3536### 2) Apply baseline mappings3738- Run:39 - `bash "scripts/switch-code-editor.sh" --editor "Cursor"`40- This applies:41 - Core UTIs (`public.text`, `public.plain-text`, `public.source-code`, etc.)42 - Baseline code/config extensions (`ts`, `tsx`, `js`, `json`, `yaml`, `sql`, `py`, `css`, `toml`, `mdx`, etc.)43 - No-extension names like `Dockerfile`4445### 3) Add project-driven coverage (preview first)4647- Preview discovered tokens before applying (required):48 - `bash "scripts/discover-project-editor-tokens.sh" "$HOME/Developer/fmd-labs/viral-app"`49 - `bash "scripts/discover-project-editor-tokens.sh" "$HOME/Developer/fmd-labs/viral-app" | sed -n '1,120p'`50- Optional safety check for obvious artifact noise:51 - `bash "scripts/discover-project-editor-tokens.sh" "$HOME/Developer/fmd-labs/viral-app" | rg '^(dep-|build-script-|bin$|a$|d$)'`52- Only after preview/review, apply project scan:53 - `bash "scripts/switch-code-editor.sh" --editor "Cursor" --project "$HOME/Developer/fmd-labs/viral-app"`54- If preview output is noisy, narrow `--project` to a cleaner subdirectory or expand excludes first.5556### 4) Verify5758- Check representative mappings:59 - `duti -x ts`60 - `duti -x tsx`61 - `duti -x env`62 - `duti -x gitignore`63 - `duti -x Dockerfile`64- If Finder still opens old handlers, log out/in to refresh LaunchServices behavior.6566### 5) Optional aggressive mode6768- Only if explicitly requested:69 - `bash "scripts/switch-code-editor.sh" --editor "Cursor" --apply-public-data`70- Warning: this can redirect many non-code files.7172## Known edge cases7374- `.ts` can resolve to a non-code UTI on some systems; extension mapping is required.75- Dotfiles like `.env.local` are often matched by suffix (`local`) plus text UTIs.76- Some apps may reclaim specific extensions after updates/reinstalls.7778## Deliverables7980When using this skill, always return:8182- Target editor and resolved bundle ID.83- Exact script command used.84- Summary of UTI + token mappings applied.85- 3-5 verification checks (`duti -x ...`).8687## Progressive disclosure8889Load only what is needed:9091- `references/coverage-from-viral-app.md` for practical extension gaps.92- `references/sources.md` for source links and version checkpoints.93- `scripts/discover-project-editor-tokens.sh` for token discovery.94- `scripts/switch-code-editor.sh` for the full apply workflow.