jdberry / tag

A command line tool to manipulate tags on Mac OS X files, and to query for files with those tags.
MIT License
1.45k stars 93 forks source link

is it possible to see which tags have been used more recently? #36

Closed foice closed 6 years ago

foice commented 6 years ago

Hi I would like to list tags of a set of files, possibly all the tagged files in my computer, and list these tags according to the date of last use. I may assume that the last use corresponds to the latest modification time of files tagged with a given tag, but this is an assumption ... is the tagging "history" somehow accessible anywhere?

jdberry commented 6 years ago

There is no metadata associated with a tag that tells when it was last used. There are, as you say, various dates associated with access and modification of the file, but these don't necessarily correlate to use of the file via a tag or tags.

It would be possible to discover files that are tagged in some way or another, and then sort them via access date, though you can't do that directly via the tag tool. You could create a pipeline something like this to match files tagged with atagname and then sort them by access time, for instance:

tag -m atagname -0 | xargs -0 ls -1tu

Note that with this approach you'll run into limitations based on the number of parameters that can be passed to ls via xargs. You could get fancier by having ls emit the file name and the appropriate timestamps, and then add an additional stage to the pipeline, calling sort to sort by the appropriate field. This is left as an exercise to the reader.

foice commented 6 years ago

I was trying similar pipes, or two lines scripts to be a bit more refined, but the only way to go would be to access the tag-mtime. I have no experience with xattr but it does not seem to be part of the tag com.apple.metadata:_kMDItemUserTags. Is it conceivable to put a custom xattr onto the file when one add/delete/modify com.apple.metadata:_kMDItemUserTags ?

jdberry commented 6 years ago

Sorry, @foice, not really sure what you're asking there. If you know you're changing the tags on the file then yes, you could add some other tag or xattribute on the file to indicate that it's been changed, or even to store the date at which it's been changed. But that approach would assume you're controlling all access to the file, or don't care about monitoring other access to the file.

foice commented 6 years ago

Sorry for the unclear phrasing. I meant to ask if tag might be extended as to add custom tags besides com.apple.metadata:_kMDItemUserTags. I think using xattr -w in a script I can do it, but I was wondering if would be interesting to extend tag features to deal with custom tags, maybe adding features such as automatic date keeping of the tags. In this way tag could keep a list of tags in parallel to the standard ones with extra info, for instance have a list of tags and their date of creation. So now I am doing tag -a "my tag goes here" myfile followed by xattr -w tag_mtime "[my tag goes here, $(date -u)"] myfile Of course I can script this line in my scripts for tag managing, but I thought it could be an intersting feature to add to tag to keep this more informative list of tags with some extra info such as modification time.

foice commented 6 years ago

Just to add some context. Adding keywords/tags to files is most useful when you give the same tag to files that are meant to be tagged in the same category. If you use variants such as my-tag, my tag, MyTag, and my_tag chances are that you will be less efficient to retrieve these files. My strategy to avoid variants is to keep a list of the tags that I use. One useful way to keep and use this list is to look at tags that have been used recently, so I can see that I have used recently my tag and I will use that instead of a variant that in that moment may make more sense to me. I hope this makes more clear what I am trying to achieve.