-
-
Notifications
You must be signed in to change notification settings - Fork 3
Description
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:
- https://github.com/tsonglew/dutis
-
A command-line tool to select default applications
-
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:
- Opening SwiftDefaultApps on Monterey makes it so you have to force quit System Preferences Lord-Kamina/SwiftDefaultApps#52
- System Preference pane crashes immediately Lord-Kamina/SwiftDefaultApps#39
- Request: Add option to import/export settings. Lord-Kamina/SwiftDefaultApps#22
- Running commands through MDM Lord-Kamina/SwiftDefaultApps#29
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.
- https://aporlebeke.wordpress.com/2020/07/16/configuring-a-macs-default-apps-for-different-file-types/
-
SwiftDefaultApps includes two tools: a command-line binary (
swda) and a preference pane. If your intent is only to set or maintain certain administrative defaults, the command-line tool is sufficient. The preference pane is only needed if you want to also provide a user-friendly interface for handling these changes.
-
Or we could just take a more manual/lower level approach:
- https://superuser.com/questions/273756/how-to-change-default-app-for-all-files-of-particular-file-type-through-terminal
- https://apple.stackexchange.com/questions/9866/programmatically-script-atically-changing-the-default-open-with-setting
- https://apple.stackexchange.com/questions/49532/change-the-default-application-for-a-file-extension-via-script-command-line
- https://ss64.com/osx/mdls.html
-
List the metadata attributes for a specified file.
-
mdls -name kMDItemCFBundleIdentifier /Applications/Sublime\ Text.appmdls -name kMDItemContentType -name kMDItemContentTypeTree ~/Desktop/foo.txtdefaults write com.apple.LaunchServices LSHandlers -array-add '{ LSHandlerContentType = \"public.plain-text\"; LSHandlerRoleAll = \"com.sublimetext.4\"; }'/System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/LaunchServices.framework/Versions/Current/Support/lsregister -kill -r -domain local -domain system -domain user
- https://ss64.com/osx/mdls.html
- https://stackoverflow.com/questions/9172226/how-to-set-default-application-for-specific-file-types-in-mac-os-x
- https://en.wikipedia.org/wiki/Uniform_Type_Identifier
- https://developer.apple.com/documentation/foundation/userdefaults
- https://support.apple.com/en-in/guide/terminal/apda49a1bb2-577e-4721-8f25-ffc0836f6997/mac
- https://ss64.com/osx/defaults.html
-
Preferences are stored in a set of files under
~/Library/Preferences, however using thedefaultscommand is much safer than manually editing a.plistfile. Thecfprefsddaemon manages and caches updates to preference files. If you modify the file directly, the changes will not propagate through the cache managed by the daemon. -
A long list of preferences that can be set in macOS and macOS applications can be found over in the How-to section.
-
- https://macos-defaults.com/
- https://github.com/kevinSuttle/macOS-Defaults/blob/master/REFERENCE.md