Hazel for hackers
github.com
github.com
rule 'Trash old temporary files' do
dir('~/Outbox/*.tmp.*').each do |p|
trash(p) if 1.week.since?(modified_at(p))
end
end
can be replaced with: #Trash old temporary files
find ~/Outbox/ -iname '*.tmp.*' -mtime +7 -exec mv {} ~/.Trash \;
The maid script may be more readable if you don't know 'find', but on the other hand, this has only one line.There are other benefits beyond logging and an easy to invoke "dry run" option. For example, many of the methods in the DSL give back arrays and strings, any of Ruby's many Enumerable methods are available to you. If you have any difficult-to-express logic, that can be quite handy. Also, not every OS keeps its trash at `~/.Trash`, but Maid will do the right thing on OS X or Linux.
There are other reasons you might prefer Maid over shell scripts, but in general my hope is that Maid can provide a common framework for these types of scripts and also a community for people interested in automating tasks like this.
$ git clean
fatal: clean.requireForce defaults to true and neither -n nor -f given; refusing to clean maid clean
# Give error message
maid clean --noop
# Show what would happen
maid clean --force # or maybe --execute
# Do actions
I'll be making an issue for this if no one has already.Safari on OS X puts the source link of a downloaded file in the spotlight metadata, which can be accessed via "mdls" - an excerpt:
$ mdls Inconsolata-Bold.ttf
-- other metadata --
kMDItemWhereFroms = (
"http://googlefontdirectory.googlecode.com/hg/ofl/inconsolata/Inconsolata-Bold.ttf,
"http://code.google.com/p/googlefontdirectory/source/browse/ofl/inconsolata/Inconsolata-Bold.ttf
)
Personally, I'd find that much more useful than the "all pdf's are books" example. Maid.rules do
rule 'Old files downloaded while developing/testing' do
dir('~/Downloads/*').each do |path|
if downloaded_from(path).any? {|u| u.match 'http://localhost'} && 1.week.since?(last_accessed(path))
trash(path)
end
end
end
endOn reboot all the stuff you didn't care about is gone.
That said, I would definitely accept help in adding event-driven rules!
Will have to give it a try...
https://github.com/benjaminoakes/maid-example
I hope it helps!Ben
Is it really that hard to just, you know, delete a few files whenever you download something? Download X. Okay. Download Y, go to open Y, delete X while you're there.
Somehow I have 6 TB of data and it's all organized. I don't have any files on my Desktop or Downloads folder. Amazingly, I don't have to spend 4 minutes looking for something when I need to pull something up to look at it or send to a friend.
Maid isn't only for cleaning up Downloads, etc. -- it may even be helpful for drivebyacct2 to organize things in other ways. For example, this is a Maid script I've reused many times when handling SRT files for videos:
https://github.com/benjaminoakes/maid-example/blob/master/rename_from_srt.rb
But if you have a workflow that already works well, more power to you. :)That said, Maid has certainly helped me out, and I'm happy that so many others have found it intriguing. (Thanks for the comments!)