Skip to content

Instantly share code, notes, and snippets.

@mattlong
Created April 16, 2026 18:11
Show Gist options
  • Select an option

  • Save mattlong/ba41a71659de24d2de696c85d414cf57 to your computer and use it in GitHub Desktop.

Select an option

Save mattlong/ba41a71659de24d2de696c85d414cf57 to your computer and use it in GitHub Desktop.
Setup MacOS file extension app associations
#!/usr/bin/env bash
# Set up the default application for file types.
# Strict mode: https://gist.github.com/vncsna/64825d5609c146e80de8b1fd623011ca
set -euo pipefail
# grab Cursor's bundle-ID
BUNDLE_ID=$(osascript -e 'id of app "Cursor"')
EXTENSIONS=(
# Code
ts
tsx
js
mjs
py
sh
# Web
css
svg
# Data / Config
json
yaml
yml
xml
csv
hcl
tf
tfvars
tpl
properties
conf
# Documentation / Text
md
mdx
txt
patch
# FHIR / Healthcare
fsh
)
# Check if duti is installed, if not, install it using Homebrew
if ! command -v duti >/dev/null 2>&1; then
echo "duti not found. Installing with Homebrew..."
exit 1
fi
# Show what will be applied and ask for confirmation
echo ""
echo "Will set Cursor ($BUNDLE_ID) as default for:"
printf " .%s\n" "${EXTENSIONS[@]}"
echo ""
read -rp "Apply these defaults? [y/N] " confirm
if [[ "$confirm" != [yY] ]]; then
echo "Aborted."
exit 0
fi
# Apply defaults one at a time so failures on individual extensions don't stop the rest
failed=()
for ext in "${EXTENSIONS[@]}"; do
if duti -s "$BUNDLE_ID" ".$ext" all 2>/dev/null; then
echo " .$ext ‚úì"
else
echo " .$ext ‚úó (no registered UTI)"
failed+=("$ext")
fi
done
if [[ ${#failed[@]} -gt 0 ]]; then
echo ""
echo "Some extensions failed because macOS has no registered UTI for them."
echo "These will still open in Cursor if you open them via the terminal (e.g. 'cursor file.ts')."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment