Topic: https://brettterpstra.com/2013/12/20/automatic-filing-with-hazel-and-mavericks-tags/
hide preview

What's next? verify your email address for reply notifications!

Fabian 11y, 83d ago

This is awesome Brett. The more I use it the more I love it!

I notice in the post that one of your primary contexts is Archive and was curious about how archiving works within this system. Do you replicate your directory structure under the Archive head context and move files across into the archive as they get old? (i.e. does a file tagged =Project :contract:pearson ultimately transition to =Archive :project:contract:pearson?

Initially I was thinking I wouldnt bother with archiving and just use file attributes (date created/modified) to sort or weed out older files in my search. However, thinking that I might face disk space issues on my air and archiving might be necessary. Probably has the side benefit of decluttering the shallow folder heirarchy with files that are years old.

hide preview

What's next? verify your email address for reply notifications!

fymalain 11y, 84d ago

Very nice.

hide preview

What's next? verify your email address for reply notifications!

Alexey 11y, 88d ago

It's working great only with Latin symbols. :) Is it possible to change script for Cyrillic? I'm not good in Ruby. Where do I look for fix it?

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 88d ago

I always forget to check that. I'll add some encoding handling in and post it tomorrow.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 87d ago

It looks like most of the issues are actually coming from the way the `mdls` command returns UTF-8 characters from the shell (as escaped UTF codes), and nothing I do seems to allow me to unescape them. Thus it creates bizarre folder names and tags, and doesn't find matches where it needs to. I'll keep playing with it, but at this point I don't have a solution.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Alexey 11y, 87d ago

Thank you for trying. Will work with Latin. :)

remark link parent

load more (1 remarks)
hide preview

What's next? verify your email address for reply notifications!

Alexey 11y, 44d ago

I find a solution. I've installed Tag (https://github.com/jdberry/... and change your code in 42 line to:

tags = %x{tag -N "#{file_path}"}.split(',').map {|tag| tag.strip.gsub(/"(.*?)"/,"\\1")}

And now it works Great! Thank you once more for great job!

hide preview

What's next? verify your email address for reply notifications!

Ted Wise 11y, 89d ago

You inspired me to retroactively build out a tagging directory structure. So I had to write a script to accomplish that - https://gist.github.com/ano...

It walks through a directory structure, constructing tag names for the directories and tagging the files in the directories. It's intended to be used in a top-level context directory and will walk down from there, e.g., tagger.rb "#work".

hide preview

What's next? verify your email address for reply notifications!

Patrick Ahles 11y, 89d ago

Working like a charm. Now I just have to remember to tag the files I save on my Desktop!

hide preview

What's next? verify your email address for reply notifications!

Ted Wise 11y, 90d ago

Doesn't work for context directories that have spaces in them. Line 34:

targets= %x{for file in $(mdfind 'kMDItemUserTags == "=*"'); do mdls -raw -name kMDItemUserTags "$file"|grep '='|tr -d '."'|sed 's/^ *//'; done}.split("\n")

needs to be changed to this:

targets= %x{mdfind 'kMDItemUserTags == "=*"' -0 | xargs -L1 -0 mdls -raw -name kMDItemUserTags | grep "=" | tr -d '."' | sed 's/^ *//'}.split("\n")

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 89d ago

Didn't even consider it because context tags with spaces require quoting in searches and that's a pain in the butt. But I'll update the gist, thanks for the code.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Ted Wise 11y, 89d ago

It's not the tags themselves, it's the filenames they're attached to. For example: Directory 'Special Stuff", tag '=specialstuff'. The (for file in) doesn't work for file names with spaces in them. That's why it needs to switch to using zero-terminators (-0).

remark link parent
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 89d ago

Yeah, realized that was the case when I was updating the gist. Good call, thanks for the tweak.

hide preview

What's next? verify your email address for reply notifications!

Dominic Zarlengo 11y, 90d ago

Working like a beauty! I am absolutely loving it. Just what I was looking for!

hide preview

What's next? verify your email address for reply notifications!

Robert Olian 11y, 90d ago

I can't get this to work by embedding a copy of the script in a Hazel action. It works fine if I run the command line you suggest. Does something in the script need to be changed to accomodate Hazel's directive to use $1to refer to the file being processed? If you are calling the script in Hazel some way other than embedding it, could you please post a screenshot of your Hazel rule. This is a great idea, and I'd obviously not want to have to do this file by file from the command line. Thanks much.

remark link
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 90d ago

My mistake, you need to run it as an external script to work as is. I'll update the post to reflect that.

I run it as external, but I was thinking it would function the same embedded. You're right, it would probably have to be altered with the $1 somehow.

remark link parent
hide preview

What's next? verify your email address for reply notifications!

Robert Olian 11y, 90d ago

OK, I wanted to run it as external but when I use the Hazel "run shell script/other" action, the tagfiler.rb is grayed out and non-selectable. Same problem if I change extension to .sh
Any idea what I am missing here?

remark link parent
hide preview

What's next? verify your email address for reply notifications!

ttscoff 11y, 90d ago

Try running `chmod a+x` on the file. e.g. `chmod a+x ~/scripts/tagfiler.rb`.

remark link parent

load more (1 remarks)
hide preview

What's next? verify your email address for reply notifications!

Robert Olian 11y, 90d ago

That did the trick. A.ll working perfectly now. Thanks ever so much

hide preview

What's next? verify your email address for reply notifications!