Created
October 24, 2021 18:00
-
-
Save jansroka/31ff53cc7459cc86491c3c29a6e7a7e6 to your computer and use it in GitHub Desktop.
Set default applications on OSX via duti
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This file is based on: | |
#======================================================================== | |
# FILE: set_default_apps.sh | |
# DESCRIPTION: Changes default apps for extensions | |
# AUTHOR: Scott Granneman (RSG), scott@chainsawonatireswing.com | |
# COMPANY: Chainsaw on a Tire Swing (http://ChainsawOnATireSwing.com) | |
# VERSION: 0.1 | |
# CREATED: 09/17/2012 21:44:01 CDT | |
# REVISION: | |
#======================================================================== | |
# Source: https://www.chainsawonatireswing.com/2012/09/19/changing-default-applications-on-a-mac-using-the-command-line-then-a-shell-script/ | |
# | |
# This script needs duti to be installed (brew install duti) | |
# | |
# Find out which app is set to do stuff by running "duti -x .avi" | |
# | |
{ cat <<eof | |
com.macpaw.site.theunarchiver:zip | |
com.macpaw.site.theunarchiver:rar | |
com.macpaw.site.theunarchiver:tar | |
com.macpaw.site.theunarchiver:zip | |
com.sublimetext.4:markdown | |
com.sublimetext.4:md | |
com.sublimetext.4:mdwn | |
com.sublimetext.4:mediawiki | |
com.sublimetext.4:sh | |
com.sublimetext.4:text | |
com.sublimetext.4:txt | |
com.sublimetext.4:sh | |
com.sublimetext.4:py | |
com.sublimetext.4:xml | |
com.sublimetext.4:ini | |
com.sublimetext.4:cfg | |
com.sublimetext.4:php | |
com.sublimetext.4:gpx | |
com.sublimetext.4:js | |
com.sublimetext.4:cfg | |
com.sublimetext.4:json | |
com.sublimetext.4:gitignore | |
com.sublimetext.4:njk | |
com.sublimetext.4:json | |
com.sublimetext.4:scss | |
com.sublimetext.4:njk | |
com.sublimetext.4:rb | |
org.videolan.vlc:mkv | |
org.videolan.vlc:avi | |
org.videolan.vlc:mp4 | |
org.videolan.vlc:mpeg | |
eof | |
} | grep . | | |
while IFS=$':' read bundle_id extension ; do | |
# Grep to see if Bundle ID exists, sending stdout to /dev/null | |
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump | grep $bundle_id > /dev/null | |
# Save exit status (0=success & 1=failure) | |
status=$? | |
# If exit status failed, notify me & exit; if not, change default app for extension | |
if test $status -eq 1 ; then | |
echo "$bundle_id doesn't exist! Fix the script!" | |
exit | |
else | |
echo -e "\nChanging $extension so it opens with $bundle_id …\n" | |
duti -s $bundle_id .$extension all | |
echo -e "Here's proof…\n" | |
duti -x $extension | |
echo -e "\n------------------------" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment