helloSystem / launch

Command line tool to launch applications, will search for .app bundles and .AppDir directories in various directories, and will show launch errors in the GUI
BSD 2-Clause "Simplified" License
16 stars 6 forks source link

Use FreeBSD extattrs to store file association information #3

Open probonopd opened 3 years ago

probonopd commented 3 years ago

Investigate FreeBSD xattrs to store file association information. Especially how Haiku uses them (hybrid with resources).

Use case:

https://www.freebsd.org/cgi/man.cgi?query=getextattr&sektion=8&apropos=0&manpath=FreeBSD+11.2-RELEASE

probonopd commented 3 years ago

nephele on IRC suggests:

it's a much nicer alternative than, like... shell scripts to invoke programms with, just put the options, or args you want in an attribute and set the correct mimetype, the programm gets that file and can understand what to do

i.e a link to open a vnc desktop to a specific host or so

haiku just sniffs the mimetyp on the first time around, and then saves it in an xattr
and then opens based on the mimetype
probonopd commented 3 years ago

Regarding (2) maybe we can set key openWith to value /Applications/LibreOffice 3.app on the file "this.doc"?

This will break when /This/App.app moves. But maybe we can set a UUID attribute on /Applications/LibreOffice 3.app and set an openWithUUID attribute on this.doc...

This needs more thought.

Regarding (1) nephele on IRC suggests:

i would just save the mimetype on the files, and then look up what to launch that mimetype with

For "look up" we might still need a (sqlite)? database.

On the Mac, Launch Services holds information about file types and the applications that should be used to open them in a database stored at /private/var/folders/**/**/-Caches-/com.apple.LaunchServices-*.csstore.

It could hold an ordered list of applications that the user would like to use, if the drive is unmounted prompt them to select the 2nd, or 3rd entry from your list or so. We could even prompt the user "Please insert disk XYZ that contains LibreOffice 3 to open this.doc"... similar to what the Classic Mac could do.

An example of a Haiku sniffer rule: https://git.haiku-os.org/haiku/tree/src/data/mime_db/video/mp4

There is probably much more to learn from Haiku in this regard: https://medium.com/@probonopd/my-sixth-day-with-haiku-under-the-hood-of-resources-icons-and-packages-abec8d0e4ec6

probonopd commented 3 years ago
# Write an extended attribute
setextattr user open-with kwrite /home/user/Schreibtisch/TODO.txt

# Read an extended attribute
getextattr -q user open-with /home/user/Schreibtisch/TODO.txt
kwrite

# List extended attributes
lsextattr -q user /home/user/Schreibtisch/TODO.txt
open-with
probonopd commented 3 years ago

This can even be done for multiple files at once:

lsextattr user /home/user/Schreibtisch/* 
/home/user/Schreibtisch/Computer.app
/home/user/Schreibtisch/menu.ui
/home/user/Schreibtisch/proof-of-concept.sh
/home/user/Schreibtisch/TODO.txt        open-with
probonopd commented 3 years ago

So in a nutshell, extended attributes allow "additional labels to be associated with a file or directory". Like which application to open a document with!

probonopd commented 3 years ago

Usage example for how to use this programmatically in a "cross-platform" way:

https://github.com/KDE/kfilemetadata/blob/master/src/xattr_p.h

Looks like it could work on Linux similarly. To be investigated.

probonopd commented 1 year ago

It's beginning to happen. launch now makes heavy use of extended attributes, and the code seems to be somewhat platform independent since it at least builds on Alpine Linux as well.

Current thinking: https://github.com/helloSystem/hello/wiki/Project-%22XDG-ng%22