Hacker News new | past | comments | ask | show | jobs | submit login
Hazel for hackers (github.com/benjaminoakes)
64 points by nicoritschel on Dec 16, 2012 | hide | past | favorite | 25 comments



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.


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.


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.


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


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.



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.


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


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.


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


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!


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.


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

Will have to give it a try...


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


Arduino to the rescue? :)


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


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

   https://github.com/benjaminoakes/maid-example
I hope it helps!

Ben


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.


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.


Maid (and Hazel) certainly aren't for everyone. The original intent behind making Maid was to automate part of what drivebyacct2 describes. I just got tired of manually doing things that could be easily automated. :)

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. :)


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.


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.


I can certainly see where you're coming from. Many of those people would probably benefit from Hazel more than Maid, however. :) As it stands, Maid is somewhere in between hand-crafted shell scripts and a user-friendly GUI (but definitely closer to the former).

That said, Maid has certainly helped me out, and I'm happy that so many others have found it intriguing. (Thanks for the comments!)


I don't see why computer skills and meticulous organizing would be correlated. I usually see the opposite, in fact.


After 1.5 years of lurking, I created an account to upvote this.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: