Informasi ini disimpan dalam garpu sumber daya file ( Wikipedia ). Garpu sumber daya ini diekspos sebagai atribut diperluas ( Wikipedia ):
$ ls -l@ somefile.txt
-rw-r--r-- 1 danielbeck staff 0 18 Mär 19:00 somefile.txt
# setting non-default application using Finder
$ ls -l@ somefile.txt
-rw-r--r--@ 1 danielbeck staff 0 18 Mär 19:01 somefile.txt
com.apple.ResourceFork 1338
Mengedit dari awal mungkin cukup menyakitkan - banyak data biner:
$ xattr -p com.apple.ResourceFork somefile.txt
00 00 01 00 00 00 05 08 00 00 04 08 00 00 00 32
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 04 04 00 00 00 32 2F 55 73 65 72 73 2F 64
61 6E 69 65 6C 62 65 63 6B 2F 41 70 70 6C 69 63
61 74 69 6F 6E 73 2F 53 75 62 6C 69 6D 65 20 54
65 78 74 20 32 2E 61 70 70 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 01 00 00 00 05 08
00 00 04 08 00 00 00 32 0C 00 00 00 C0 05 00 00
00 1C 00 32 00 00 75 73 72 6F 00 00 00 0A 00 00
FF FF 00 00 00 00 19 00 00 00
Tetapi Anda dapat memperlakukan garpu sumber daya ini seperti file. Sebagai contoh:
$ open somefile.txt # opens in Sublime 2
$ cp somefile.txt/..namedfork/rsrc openInSublime2rsrc
$ open otherfile.txt # opens in TextEdit
$ cp openInSublime2rsrc otherfile.txt/..namedfork/rsrc
$ open otherfile.txt # opens in Sublime 2
/..namedfork/rsrc
adalah bagaimana garpu sumber daya terpapar ke aplikasi POSIX (mis. mungkin semua yang Anda lakukan di Terminal).
Jadi, Anda hanya perlu membuat satu file "templat" dari garpu sumber daya yang ada (dalam contoh ini openInSublime2rsrc
), dan Anda dapat menyalinnya ke file lain setelahnya.
somefile.txt/..namedfork/rsrc
saja.somefile.txt/rsrc
telah ditinggalkan beberapa waktu lalu.Mengambil dari jawaban Daniel Beck di atas, informasi ini memang disimpan dalam garpu sumber daya file. Apple menyediakan dua utilitas, yang disebut "Rez" dan "DeRez" dengan alat pengembang, yang memungkinkan Anda untuk memanipulasi garpu sumber daya. Secara khusus, Anda dapat mendorong garpu sumber daya ke file dengan Rez.
Untuk mengubah kaitan satu file dari baris perintah, pertama buat file dengan tipe yang tepat, dan secara manual ubah kaitannya dengan aplikasi yang Anda inginkan. Ini menciptakan garpu sumber daya dalam file - jika Anda tidak mau t melakukan ini, tidak akan ada informasi untuk disalin. Kemudian, tarik garpu sumber daya dengan DeRez, seperti ini (dengan asumsi file foo.txt, dan aplikasi yang ingin Anda gunakan adalah Firefox.app).
Ini akan membuat file bernama foo.r yang merupakan fork resource dekompilasi sebagai file teks. Akan terlihat seperti ini:
Anda dapat mengedit ini jika Anda ingin membuat satu dari awal, tetapi Anda harus mendapatkan format persis benar atau tidak akan bekerja. Itu hanya karakter hex-encoded yang menggambarkan jalur ke bundel aplikasi yang Anda inginkan, diakhiri dengan nol.
Anda mungkin melihat pesan yang mengatakan bahwa garpu sumber daya kosong dan belum diinisialisasi. Jika demikian, Anda belum mengubah asosiasi per-file pada file sumber, jadi Anda harus melakukannya, lalu jalankan kembali perintah DeRez.
Setelah Anda memiliki ini, Anda dapat mendorong ini ke file lain sebagai berikut (dengan asumsi bar.txt ada):
Bar.txt ini diperbarui di tempat dengan garpu sumber daya dari foo.r.
Untuk memeriksanya berfungsi dengan baik, karena baik Rez maupun DeRez tidak mencetak pesan kesalahan, lakukan saja ini:
Anda harus melihat informasi yang sama seperti sebelumnya. Setelah semua itu, cukup buka file bar.txt seperti biasa, dan itu akan terbuka di aplikasi yang benar, bukan yang default.
Untuk melakukan perubahan batch, setelah Anda memiliki file .r, maka Anda dapat menggunakan ekspansi wildcard standar seperti ini:
Itu akan melakukan semua file yang cocok dengan wildcard.
Saya telah melakukan ini pada 10.7, tetapi ini adalah pemahaman saya bahwa ini bekerja pada mesin sebelumnya juga.
sumber
..namedfork/rsrc
, benar? Anda berdagang yang membutuhkan pengetahuan tentang (semi) internal untuk pengetahuan tentang alat khusus - saya tidak yakin ini lebih baik.Saya melakukannya menggunakan xattr (berfungsi dengan baik pada volume APFS)
Lihat topik ini jika Anda membutuhkan lebih banyak
sumber
Anda mengatakan Anda ingin "mengubah batch" aplikasi yang terkait dengan set (sub-) file tertentu, dari tipe tertentu. sub-set karena Anda tidak ingin mengubah semua instance dari jenis file itu ke aplikasi baru itu.
Namun, tidak ada cara mudah untuk melakukan ini. Cara bagaimana LaunchServices menemukan aplikasi mana yang harus diberitahu untuk membuka file adalah proses multistage, dan tergantung pada pengaturan dengan cakupan yang berbeda (pengguna, sistem dan sebagainya).
Tetapi - Anda dapat menggunakan
open
pada commandline dan menyuruhnya untuk menggunakan aplikasi tertentu saat ini. Ini tidak akan mengubah asosiasi apa pun, tetapi itu akan mencapai apa yang Anda katakan Anda inginkan, yaitu membuka satu set file dalam aplikasi tertentu:open -a <appbundle> <somefile> <anotherfile>
Suka
dan, pergi sepenuhnya dari baris perintah: lihat utilitas ini: http://michelf.com/software/magic-launch/
sumber
open -a TextWrangler *
akan lebih cepat.