Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there anything more convenient than using RCDefaultApp or Magic Launch, or just repeatedly pressing the Change All buttons in Finder's information panels?

I thought about writing a shell script that would modify the CFBundleDocumentTypes arrays in Info.plist files. But each app has multiple keys (sometimes an icon) that would need to be changed.

lsregister can't be used to make specific modifications to the Launch Services database.

$ `locate lsregister` -h
lsregister: [OPTIONS] [ <path>... ]
                      [ -apps <domain>[,domain]... ]
                      [ -libs <domain>[,domain]... ]
                      [ -all  <domain>[,domain]... ]

Paths are searched for applications to register with the Launch Service database.
Valid domains are "system", "local", "network" and "user". Domains can also
be specified using only the first letter.

  -kill     Reset the Launch Services database before doing anything else
  -seed     If database isn't seeded, scan default locations for applications and libraries to register
  -lint     Print information about plist errors while registering bundles
  -convert  Register apps found in older LS database files
  -lazy n   Sleep for n seconds before registering/scanning
  -r        Recursive directory scan, do not recurse into packages or invisible directories
  -R        Recursive directory scan, descending into packages and invisible directories
  -f        force-update registration even if mod date is unchanged
  -u        unregister instead of register
  -v        Display progress information
  -dump     Display full database contents after registration
  -h        Display this help
share|improve this question
    
Awesome work Lauri, the net is awash with people suggesting Cmd-i, Change All. I'll give duti a whirl next time I try out another App that re-registers dozens of file types. –  Slomojo Jul 3 '12 at 2:44

3 Answers 3

Unfortunately, since the resource forks inside the files in Mac OS X are being phased out, I don't think that there is an easy way to do this. There really should be, though. Keep us posted on your script. It should be just what we all need.

share|improve this answer
    
I didn't mean changing the associations of individual files, but like associating all .avis with VLC. –  ؘؘؘؘ Aug 17 '11 at 22:22
    
Then use the "Change All..." button in the dialog shown above. That should change the default association. –  mauvedeity Oct 8 '11 at 8:45

You can change what application opens all AVIs quite easily, no scripting required. Find an AVI file, and do Get Info on it. This will show you the file information. Select the program you want to open the files, then click the "Change All..." button. That will prompt you to change the default association. enter image description here

Just as a small point, resource forks aren't being phased out, but creator codes are. As such, newer Mac OS systems have a more flexible system for working out how to open files. Applications are supposed to work on files that don't have resource forks, but some applications still use them.

share|improve this answer
    
Changing the default app from an information dialog requires about 10 mouse or keyboard actions. That gets pretty annoying after the first few hundred times or so. –  ؘؘؘؘ Sep 29 '11 at 23:03
    
In that case, see this answer elsewhere on the site, it'll show you how to do a command line batch change. –  mauvedeity Oct 8 '11 at 8:44
    
(The linked answer is about about changing the default app of a single file from its resource fork.) Even if I modified the resource forks of all of my existing files, it wouldn't change the default apps of files I will have in the future. –  ؘؘؘؘ Oct 8 '11 at 8:58
up vote 5 down vote accepted

duti

  1. Download the pkg installer or compile from source
  2. Save a file like this somewhere:

    com.macromates.textmate public.shell-script all
    com.macromates.textmate public.unix-executable all
    com.macromates.textmate com.apple.property-list all
    org.videolan.vlc .avi all
    org.videolan.vlc .mkv all
    # ...
    
  3. duti $file.duti

Finding bundle identifiers or UTIs:

bundleid() {
  osascript -e "id of app \"$*\""
}

getuti() {
  local f="/tmp/me.lri.getuti.${1##*.}"
  touch "$f"
  mdimport "$f"
  mdls -name kMDItemContentTypeTree "$f"
  rm "$f"
}

lsapps

I wrote a Ruby script a lot like duti before I found out about it. It requires restarting the OS to apply the changes though. It also overwrites any external changes to com.apple.LaunchServices.plist.

#!/usr/bin/env ruby

datafile = "#{ENV['HOME']}/Notes/lsapps.txt"
cachedir = "#{ENV['HOME']}/Library/Caches/me.lri.scripts"
cachefile = cachedir + "/lsapps"
`mkdir -p #{cachedir}; touch #{cachefile}`
cachetext = IO.read(cachefile)

a = []
IO.readlines(datafile).each do |line|
  line.strip!
  next unless line =~ /^([^#].*): (.+)/
  z = $1, $2

  bid = cachetext.scan(/#{z[0]}  (.*)/)[0]
  unless bid
    bid = `osascript -e 'id of app "#{z[0]}"'`.chomp
    next unless bid
    File.open(cachefile, "a") { |f| f.puts(z[0] + "  " + bid) }
  end

  z[1].strip.split(" ").each do |e|
    if e =~ /(.+):\/\/$/
      a << "{LSHandlerURLScheme='#{$1}';LSHandlerRoleAll='#{bid}';}"
    elsif e.include?(".")
      a << "{LSHandlerContentType='#{e}';LSHandlerRoleAll='#{bid}';}"
    else
      a << "{LSHandlerContentTag='#{e}';LSHandlerContentTagClass=\
'public.filename-extension';LSHandlerRoleAll='#{bid}';}"
    end
  end
end

system("defaults", "write", "com.apple.LaunchServices", "LSHandlers",
"(" + a.join(",") + ")")

`defaults write com.apple.LaunchServices LSQuarantine -bool false`

lsapps.txt

NetNewsWire Lite: feed:// public.rss
iCal: icaltodo icalevent
Google Chrome: chrome://
Safari: public.html
TextEdit: txt text md markdown csv
TextMate: public.shell-script public.unix-executable public.script ssh:// xml plist dict css rst tex sh pl py rb gemspec php js java c h m conf bash opml as cfm cfml class coffee ctp erb rhtml haml less msass scss yaml rd
VLC: avi mpg flv mkv mp4 flac 3gp
The Unarchiver: rar
Skim: pdf
iChm: chm
AppleScript Editor: scpt
Sequential: png jpg
share|improve this answer
    
    
Commented by @kopischke … in some cases, a restart of the operating system is not required following use of duti. –  Graham Perrin May 18 '12 at 4:57
2  
@GrahamPerrin I meant that my own Ruby script (not duti) requires restarting. I actually switched to duti mainly because it doesn't require restarting or overwrite the plist. –  ؘؘؘؘ May 18 '12 at 5:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.