0xdevalias / dotfiles

devalias does dotfiles
http://zachholman.com/2010/08/dotfiles-are-meant-to-be-forked/
MIT License
8 stars 1 forks source link

Dump/restore custom file type associations (eg. duti, SwiftDefaultApps, swda, etc) #5

Open 0xdevalias opened 4 years ago

0xdevalias commented 4 years ago

Use https://github.com/moretension/duti to dump/restore custom file type applications, though it seems as though it may not be maintained anymore:

brew install duti

# Read
⇒  duti -x md
# Xcode.app
# /Applications/Xcode.app
# com.apple.dt.Xcode

duti -x html

⇒  duti -x mp4
# VLC.app
# /Applications/VLC.app
# org.videolan.vlc

# Write

# Find the application bundle identifier
⇒  mdls -name kMDItemCFBundleIdentifier /Applications/Sublime\ Text.app
# kMDItemCFBundleIdentifier = "com.sublimetext.4"

# Extract the bundle identifier in a crude automation friendly way to make it scriptable
⇒  mdls -name kMDItemCFBundleIdentifier /Applications/Sublime\ Text.app | awk '{ gsub(/"/, "", $3); print $3}'
# com.sublimetext.4

# Extract the bundle identifier in a much better/simpler automation friendly way to make it scriptable
⇒  mdls -name kMDItemCFBundleIdentifier -raw /Applications/Sublime\ Text.app
# com.sublimetext.4%

duti -s com.sublimetext.4 .txt all
duti -s com.sublimetext.4 .md all

# Confirming that it was set correctly
⇒  duti -x md
# Sublime Text.app
# /Applications/Sublime Text.app
# com.sublimetext.4

See also:


Could also use something like https://github.com/Lord-Kamina/SwiftDefaultApps to make it easier to configure in general, though it seems to have it's own issues too:

brew install --cask swiftdefaultappsprefpane

Seemingly it also includes a CLI tool swda.

swda -h

swda getUTIs | grep public.

Or we could just take a more manual/lower level approach: