มีวิธีที่เร็วกว่าในการเปลี่ยนแอปเริ่มต้นที่เชื่อมโยงกับประเภทไฟล์ใน OS X หรือไม่


13

มีอะไรที่สะดวกกว่าการใช้RCDefaultAppหรือMagic Launchหรือเพียงแค่กดปุ่ม Change All ทั้งหมดในแผงข้อมูลของ Finder's?

ฉันคิดเกี่ยวกับการเขียนเชลล์สคริปต์ที่จะแก้ไขอาร์เรย์ CFBundleDocumentTypes ในไฟล์ Info.plist แต่แอพแต่ละตัวมีหลายปุ่ม (บางครั้งไอคอน) ที่จะต้องมีการเปลี่ยนแปลง

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 เปลี่ยนทุกอย่าง ฉันจะdutiลองอีกครั้งในคราวหน้าฉันลองใช้แอปอื่นที่ลงทะเบียนไฟล์หลายสิบประเภทอีกครั้ง
ocodo

คำตอบ:


12

Duti

  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

การค้นหาตัวระบุบันเดิลหรือ 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

ฉันเขียนสคริปต์ Ruby เหมือน duti มากก่อนที่ฉันจะค้นพบมัน มันต้องมีการรีสตาร์ทระบบปฏิบัติการเพื่อใช้การเปลี่ยนแปลง นอกจากนี้ยังเขียนทับการเปลี่ยนแปลงภายนอกใด ๆ 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
Graham Perrin

2
@ GrahamPerrin ฉันหมายความว่าสคริปต์ Ruby ของฉัน (ไม่ใช่ duti) ต้องเริ่มต้นใหม่ จริง ๆ แล้วฉันเปลี่ยนไปใช้ duti ส่วนใหญ่เพราะมันไม่จำเป็นต้องเริ่มต้นใหม่หรือเขียนทับ Plist
Lri

1

คุณสามารถเปลี่ยนแอปพลิเคชันที่เปิด AVIs ทั้งหมดได้อย่างง่ายดายโดยไม่จำเป็นต้องมีสคริปต์ ค้นหาไฟล์ AVI และรับข้อมูลบนมัน นี่จะแสดงข้อมูลไฟล์ให้คุณ เลือกโปรแกรมที่คุณต้องการเปิดไฟล์จากนั้นคลิกปุ่ม "เปลี่ยนทั้งหมด ... " ที่จะแจ้งให้คุณเปลี่ยนการเชื่อมโยงเริ่มต้น ป้อนคำอธิบายรูปภาพที่นี่

เช่นเดียวกับจุดเล็ก ๆ ส้อมทรัพยากรจะไม่ถูกเลิกใช้ แต่รหัสของผู้สร้างคือ ดังนั้นระบบ Mac OS ที่ใหม่กว่าจะมีระบบที่ยืดหยุ่นกว่าสำหรับการหาวิธีเปิดไฟล์ แอปพลิเคชันควรทำงานกับไฟล์ที่ไม่มีส้อมทรัพยากร แต่บางแอปพลิเคชันยังคงใช้งานอยู่


1
การเปลี่ยนแอพเริ่มต้นจากกล่องโต้ตอบข้อมูลต้องใช้การทำงานของเมาส์หรือคีย์บอร์ดประมาณ 10 ครั้ง มันค่อนข้างน่ารำคาญหลังจากสองสามร้อยครั้งแรก
Lri

ในกรณีดังกล่าวให้ดูคำตอบนี้ที่อื่นในเว็บไซต์มันจะแสดงวิธีการเปลี่ยนแบทช์บรรทัดคำสั่ง
mauvedeity

(คำตอบที่เชื่อมโยงนั้นเกี่ยวกับการเปลี่ยนแอพเริ่มต้นของไฟล์เดียวจากตัวแยกทรัพยากร) แม้ว่าฉันจะแก้ไขไฟล์ส้อมของไฟล์ที่มีอยู่ทั้งหมดของฉันมันก็จะไม่เปลี่ยนแอพเริ่มต้นของไฟล์ที่ฉันจะมีใน อนาคต.
Lri
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.