
Hazel for hackers - nicoritschel
https://github.com/benjaminoakes/maid
======
icebraining
Is there a great advantage over standard shell commands, besides being in
Ruby? For example, the following rule:

    
    
      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.

~~~
benjaminoakes
I used to use bash scripts and `find` for the purposes that you give. Maid
came about when I was starting to add logging and a "dry run" option to those
bash scripts. Ruby quickly became an attractive option then. But for many one-
off tasks, I still find knowing how to use `bash`, `find`, etc effectively to
be important.

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.

------
flogic
One of the areas where I disembark from the traditional Unix way is to replace
"--dry-run" like flags with "--enable-destruction". That way I have to
intentionally do the bad thing.

~~~
snprbob86

        $ git clean
        fatal: clean.requireForce defaults to true and neither -n nor -f given; refusing to clean

~~~
benjaminoakes
That's something I'll definitely consider.

    
    
        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.

~~~
benjaminoakes
This is now <https://github.com/benjaminoakes/maid/issues/78>

------
zdw
A nice feature that could be implemented on OS X would be to auto-organize
files by the domain they're downloaded from.

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.

~~~
mbudde
There's this example from the README which seems to do what you are asking
for:

    
    
        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
        end

------
mr337
Something that I recently started to do that seemed to help me it to point
downloads of FF and Chrome to /tmp. So if I downloaded something important I
immediately moved it to where it belonged.

On reboot all the stuff you didn't care about is gone.

------
andrethegiant
I like it, but prefer something like guard-shell which is event-driven:
<https://github.com/guard/guard-shell>

~~~
benjaminoakes
I'd love that as well. It's certainly something I'd like to implement... but
as of yet, I haven't come across many use cases (personally) in which it's
necessary.

That said, I would definitely accept help in adding event-driven rules!

------
Xyzodiac
I've been meaning to try maid, I installed the gem but I've yet to do anything
more. Thanks for posting this, as now I have some incentive to configure it.

------
aes256
This looks interesting. I've been using Hazel on OS X for a long time.

Will have to give it a try...

------
stratosvoukel
It looks great! yay! Now lets make something to take care of our rooms! :P

~~~
benjaminoakes
Arduino to the rescue? :)

------
terhechte
Would be great to have a repository with rules for this.

~~~
benjaminoakes
I've posted some rules that I use as an example:

    
    
       https://github.com/benjaminoakes/maid-example
    

I hope it helps!

Ben

------
drivebyacct2
This is pretty much horrifying (to someone like me who likes to meticulously
manage and know where things are instead of treating "Downloads" or "Desktop"
like a flat-filesystem.

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.

~~~
graue
Good for you. Sounds like you don't need this program. Since you're aware that
there are people who treat "Downloads" and "Desktop" like a flat filesystem,
presumably you can understand why this would be useful to them and others.

~~~
drivebyacct2
I'm guessing the people that would really benefit from it have never heard of
GitHub and think that Ruby is a precious gem. I don't mean to knock the work.

~~~
potch
If you are guessing that all engineers who understand how to use the command
line are well-organized, I can provide you at least one certified example of
one who doesn't match your worldview. This is awesome.

