Skip to content

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

@0xdevalias

Description

@0xdevalias

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

  • This will seemingly install both the prefpane and the CLI binary.

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:

See Also

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions