有什么比使用RCDefaultApp或Magic Launch更方便的,或者只是重复按下 Finder 信息面板中的“全部更改”按钮?
我想写一个 shell 脚本来修改 Info.plist 文件中的 CFBundleDocumentTypes 数组。但是每个应用程序都有多个需要更改的键(有时是一个图标)。
lsregister 不能用于对启动服务数据库进行特定修改。
$ `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
Run Code Online (Sandbox Code Playgroud)
Lri*_*Lri 12
将这样的文件保存在某处:
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
# ...
Run Code Online (Sandbox Code Playgroud)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"
}
Run Code Online (Sandbox Code Playgroud)
在我发现它之前,我写了一个很像 duti 的 Ruby 脚本。不过,它需要重新启动操作系统才能应用更改。它还会覆盖对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`
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5716 次 |
| 最近记录: |