RhetTbull / osxmetadata

Python package to read and write various MacOS extended attribute metadata such as tags/keywords and Finder comments from files. Includes CLI tool for reading/writing metadata.
MIT License
117 stars 2 forks source link

--copypairs src1 dst1 src2 dst2 src3 dst3 … and --copylist src1 src2 src3 dst1 dst2 dst3 … #73

Open porg opened 1 year ago

porg commented 1 year ago

Feature Proposal

--copypairs src1 dst1 src2 dst2 src3 dst3 …

--copylist src1 src2 src3 dst1 dst2 dst3 …

Situations of need

Intended use cases as a fruitful collaboration of Finder (GUI) & Terminal (CLI)

RhetTbull commented 1 year ago

I think you could accomplish something similar with a xargs -n or a simple shell script and copyfrom in it's current form.

Not tested but something like this:

You have a list of file pairs in a file file.txt:

src1
dest1
src2
dest2
...

Then:

cat files.txt | xargs -n 2 osxmetadata --copyfrom

porg commented 1 year ago

osxmeta --copypairs <drag n drop files here> ENTER is just so much more convenient.

But ok if I want drag'n'drop I could write a script only taking $0 (the whole input) which then puts each argument onto its own line, which then counts the numbers of lines:

But yeah, until that works with my skills, again 3-4hours are gone. Shell scripting is always frustrating as soon as whitespace, special characters etc come into play.

porg commented 1 year ago

And --copylist I guess can be done when the arguments passed as even-numbered to split them in two multi-line variables and iterate through them osxmeta --copyfrom $src(line $i) $dst(line $i). Or split into two files as /tmp/src.txt and /tmp/dst.txt and then merge them line alternatingly (surely a unix tool for this) and then run with your xargs.

RhetTbull commented 1 year ago

But yeah, until that works with my skills, again 3-4hours are gone.

But it's 10-12 hours of my time to implement and test ;-)

cat > files.txt allows you to copy and drag from Finder then press Ctrl-D when done and use that with xargs

RhetTbull commented 1 year ago

I've been thinking more about this and at least for now I do not intend to work on this. My rationale is this:

  1. This unnecessarily complicates the code (and subsequent maintenance) for a niche use case.
  2. I write a lot of CLI tools and try to follow the Unix ethos of "do one thing and do it well". Other tools can already be used to accomplish this. For example, the paste command can interleave the arguments from two files (as in your --copylist example) and combined with xargs can do the same as your --copypairs example. For example, this should work:

paste -d"\n" source.txt destination.txt | xargs -n 2 osxmetadata --copyfrom

If there's something that needs to be fixed in osxmetadata to work better with the standard unix command line tools, I'm happy to look at fixing it but I do not want to implement functionality already present in other command line tools unless there's a very good reason to do so.

paste example:

> cat files1.txt
File1-1.txt
File1-2.txt
File1-3.txt
> cat files2.txt
File2-1.txt
File2-2.txt
File2-3.txt
> paste -d"\n" files1.txt files2.txt
File1-1.txt
File2-1.txt
File1-2.txt
File2-2.txt
File1-3.txt
File2-3.txt
RhetTbull commented 1 year ago

One other option, if the source and destination files have the same name you could use osxmetadata to do a backup in the source directory, copy the .osxmetadata.json file to the destination and then do a restore.

porg commented 1 year ago

After reading all your arguments I agree that this functionality shall be achieved by interplay of unix tools, and avoid osxmeta to get to big to maintain properly.

But what we very well can do is to add those use cases and solution approaches into the readme.md or the --help or manpage. So I leave this ticket open, and when I found a solution will try to create a nice writeup, which I post here in Markdown Syntax, which you can then embed into readme/manpage/--help as you see fit.

porg commented 1 year ago

Thanks again for declining my request for the right reasons!

With great pride I present my work

RhetTbull commented 1 year ago

Looks useful! I'll take a look when I get a chance.