As mentioned above one method is to use duti
, here's a script which you could put in a crontab so when an external app changes your extensions, your script will change them back again;
1.Install duti with HomeBrew:
brew install duti
2.find all your apps bundle id's with:
mdls -name kMDItemCFBundleIdentifier -r /Applications/VLC.app
for example in this case will output: org.videolan.vlc
3.change the default app:
duti -s org.videolan.vlc .mp4 all
#!/bin/bash
#========================================================================
# 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:
#========================================================================
{ cat <<eof
com.macrabbit.Espresso:css
com.valloric.Sigil.app:epub
cx.c3.theunarchiver:gz
com.sublimetext.2:markdown
com.sublimetext.2:md
com.sublimetext.2:mdwn
com.sublimetext.2:mediawiki
cx.c3.theunarchiver:rar
com.sublimetext.2:sh
cx.c3.theunarchiver:tar
com.sublimetext.2:text
com.sublimetext.2:txt
com.sublimetext.2:xml
cx.c3.theunarchiver:zip
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
- you can find all your apps extensions with this voodoo from @Lri posted above, and then use/paste the result in the script above:
app="VLC.app" ; \
bundleid=`mdls -name kMDItemCFBundleIdentifier -r /Applications/$app` ; \
dump=$(/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump); \
plutil -convert xml1 /Applications/$app/Contents/Info.plist -o - | \
sed -n '/LSItemContentTypes/,/\/array/p' | \
sed -En 's|.*string>(.*)</string.*|\1|p' | \
while read u; do \
awk "/uti: *$u/,/tags:/" \
<<< "$dump"; done | \
sed -En 's/[[:space:]]*tags: *(.+)/\1/p' | \
sed $'s/, /\\\n/g' | \
grep '^\.' | sort -u | \
awk '{print "'$bundleid':" substr($1,2,length($1)) }'
- then put the script in a crontab that runs every x minutes/hours