OS Xでファイルの種類に関連付けられたデフォルトのアプリをより速く変更する方法はありますか?


13

RCDefaultAppMagic Launchを使用したり、Finderの情報パネルで[すべて変更]ボタンを繰り返し押したりするよりも便利なものはありますか?

Info.plistファイルのCFBundleDocumentTypes配列を変更するシェルスクリプトを書くことを考えました。ただし、各アプリには、変更が必要な複数のキー(場合によってはアイコン)があります。

lsregister Launch Servicesデータベースに特定の変更を加えるために使用することはできません。

$ `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

素晴らしい仕事Lauri、ネットはCmd-i、Change Allを提案する人々であふれています。私はあげるduti、私は別のアプリケーションのファイルタイプの再登録の数十を試してみる旋回次回。
オコド

回答:


12

ドゥティ

  1. pkgインストーラーをダウンロードするか、ソースからコンパイルします
  2. このようなファイルをどこかに保存します。

    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

バンドル識別子またはUTIの検索:

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

Rubyスクリプトは、気付く前にdutiによく似ていました。ただし、変更を適用するにはOSを再起動する必要があります。また、への外部変更を上書きします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


@kopischkeによるコメント …場合によっては、dutiの使用後にオペレーティングシステムを再起動する必要はありません
グラハムペリン

2
@GrahamPerrin私は自分のRubyスクリプト(dutiではない)の再起動が必要であることを意味しました。主に再起動やplistの上書きを必要としないため、実際にdutiに切り替えました。
リリー

1

すべてのAVIを開くアプリケーションを簡単に変更できます。スクリプトは不要です。AVIファイルを見つけて、情報を取得します。これにより、ファイル情報が表示されます。ファイルを開くプログラムを選択し、「すべてを変更...」ボタンをクリックします。デフォルトの関連付けを変更するよう求められます。 ここに画像の説明を入力してください

小さな点として、リソースフォークは段階的に廃止されていませんが、クリエーターコードは廃止されています。そのため、新しいMac OSシステムには、ファイルを開く方法を決定するためのより柔軟なシステムがあります。アプリケーションはリソースフォークを持たないファイルで動作するはずですが、一部のアプリケーションはまだそれらを使用します。


1
情報ダイアログからデフォルトのアプリを変更するには、約10のマウスまたはキーボードアクションが必要です。それは最初の数百回かそこらの後にかなり厄介になります。
リリ

その場合は、サイトの他の場所でこの回答を参照してください。コマンドラインのバッチ変更を行う方法を示します。
11

(リンクされた答えは、リソースフォークから単一ファイルのデフォルトアプリを変更することについてです。)既存のすべてのファイルのリソースフォークを変更しても、ファイルのデフォルトアプリは変更されません。未来。
-Lri
弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.