• Stars
    star
    1,727
  • Rank 26,999 (Top 0.6 %)
  • Language
    Ruby
  • License
    GNU General Publi...
  • Created over 13 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Be lazy. Let Maid clean up after you, based on rules you define. Think of it as "Hazel for hackers".

Maid

Gem Version Test Code Climate Test Coverage StackOverflow

Be lazy! Let Maid clean up after you, based on rules you define.

Installation | Tutorial | Example | User Community | Documentation | Changelog

Maid keeps files from sitting around too long, untouched. Many of the downloads and temporary files you collect can easily be categorized and handled appropriately by rules you define. Let the maid in your computer take care of the easy stuff, so you can spend more of your time on what matters.

Think of it like the email filters you might already have, but for files. Worried about things happening that you don't expect? Maid doesn't overwrite files and actions are logged so you can tell what happened.

Maid is inspired by the Mac OS X shareware program Hazel. Think of Maid as "Hazel for hackers".

Your rules are defined in Ruby, so simple rules are easy and difficult rules are possible. This also makes Maid a great general-purpose advanced file renaming tool.

Want to help?

This project wouldn't be where it is today without its users and contributors. Thank you! See AUTHORS and the contributors graph for more info.

For Users

For Developers

  • Address a TODO or FIXME in the code (list them with rake notes.)
  • Fix an existing issue
  • Working on an issue? Please leave a comment so others know.
  • See the Contributing guide

Buzz

Hacker News Logo

Hazel for hackers - December 16th, 2012 (peaked at #2)

Ruby5 Logo

Podcast #302 (at 2:45) - August 31st, 2012

OneThingWell Logo

Maid - August 29th, 2012

More...

Installation

Maid is a gem, so just gem install maid like normal. If you're unfamiliar with Ruby, please see below for details.

Requirements

Modern Ruby versions and Unix-like operating systems should work, but only OS X and Ubuntu are tested regularly.

Offically supported:

  • OS: Mac OS X, Ubuntu
  • Ruby: 2.7.0+ (3.0.0+ preferred)

Some features require OS X. See the documentation for more details.

Manual Installation

First, you need Ruby 2.7 or 3. If you're starting without any Rubies, we strongly recommend going for Ruby 3 as 2.7 is EOL.

Consider using rvm, rbenv, rtx, or any other version management tool.

Then, install via RubyGems. Open a terminal and run:

gem install maid

At a later date, you can update by running:

gem update maid

If you decide you don't want Maid installed anymore, remove it:

gem uninstall maid

NOTE: This does not remove any files under ~/.maid or crontab entries. Please remove them at your convenience.

Install through RVM and a dedicated gemset

Install Ruby 3.2 and create a gemset:

rvm install ruby-3.2 && rvm use 3.2 && rvm gemset create maid && rvm alias create maid ruby-3.2@maid

Install maid:

rvm use maid && gem install maid

Update maid:

rvm use maid && gem update maid

Update ruby:

rvm install ruby-3.3 && rvm gemset copy 3.{2,3}@maid && rvm alias maid 3.3@maid

Tutorial

In a nutshell, Maid uses "rules" to define how files are handled. Once you have rules defined, you can either test what cleaning would do (maid clean -n) or actually clean (maid clean -f).

To generate a sample rules file, run:

maid sample

Maid rules are defined using Ruby, with some common operations made easier with a small DSL (Domain Specific Language).

For example, this is a rule:

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?(accessed_at(path))
        trash(path)
      end
    end
  end
end

If you're new to Ruby and would prefer a more traditional for loop, you can also do this:

Maid.rules do
  rule 'My rule' do
    for path in dir('~/Downloads/*')
      # ...
    end
  end
end

Before you start running your rules, you'll likely want to be able to test them. Here's how:

# No actions are taken; you just see what would happen with your rules as defined.
maid clean --dry-run # Synonyms: -n, --noop

To run your rules on demand, you can run maid manually:

maid clean -f                 # Run the rules at ~/.maid/rules.rb, logging to ~/.maid/maid.log
maid clean -fr some_rules.rb  # Run the rules in the file 'some_rules.rb', logging to ~/.maid/maid.log

So, for example, if this is some_rules.rb:

Maid.rules do
  rule 'downloaded PDF books' do
    move(dir('~/Downloads/*.pdf'), '~/Books')
  end
end

Then, this is the command to test, as well as some sample output:

$ maid clean -nr some_rules.rb
Rule: downloaded PDF books
mv "/Users/ben/Downloads/book.pdf" "/Users/ben/Books/"
mv "/Users/ben/Downloads/issue12.pdf" "/Users/ben/Books/"
mv "/Users/ben/Downloads/spring2011newsletter.pdf" "/Users/ben/Books/"

For help with command line usage, run maid help. For more help, please see the links at the top of this README.

Automation

Once you get a hang for what you can do with Maid, let it do its stuff automatically throughout the day. You'll find your computer stays a little tidier with as you teach it how to handle your common files.

Note: Daemon support (using fsevent/inotify) was recently added. That said, cron takes care of the needs of many users.

To do this, edit your crontab in your tool of choice:

crontab -e

...and have it invoke the maid clean -f command. The --silent option is provided to keep this from emailing you, if desired. A log of the actions taken is kept at ~/.maid/maid.log.

Example for every day at 1am:

# minute hour day_of_month month day_of_week command_to_execute
0 1 * * * /bin/bash -li -c "maid clean --force --silent"

Running as a daemon

To run Maid as a daemon you first have to specify watch/repeat rules.

They are defined like this:

Maid.rules do
  repeat '1s' do
    rule 'This rule will run every second' do
      # some task
    end
  end

  watch '/home/user/Downloads' do
    rule 'This rule will run on every change to the downloads directory' do
      # another task
    end
  end

  watch '~/Desktop', ignore: /some_directory/ do
    # rules in here
  end
end

Here's a simple "watch" rule that organizes images by dimensions as soon as they're added to ~/Pictures:

Maid.rules do
  watch '~/Pictures' do
    rule 'organize images by dimensions' do
      where_content_type(dir('~/Pictures/*'), 'image').each do |image|
        width, height = dimensions_px(image)
        move(image, mkdir("~/Pictures/#{width}x#{height}"))
      end
    end
  end
end

The command to run the daemon is maid daemon. Starting the daemon on login depends on the platform.

With RVM and cron

See above to install RVM and maid in its own gemset.

Run maid daily in a cron:

# /etc/cron.daily/maid

#!/usr/bin/env bash
sudo -Hu <your username> bash -li -c "<your username>/.rvm/wrappers/maid/maid clean --force --silent --rules ~/.maid/rules.rb"

Ubuntu

You can run maid daemon as a normal startup application (Power/Gear Menu -> Startup Applications... -> Add).

OS X

Please see Jurriaan Pruis' blog post, Maid as a Daemon on OS X. (Automating this setup would be welcome as a pull request!)

Rake Tasks

Maid includes helpers that make file managment easier. You may find them useful if you need to automate tasks in your Ruby projects. This is available via support for Maid-based Rake tasks:

# File: Rakefile
require 'maid'

Maid::Rake::Task.new :clean do
  # Clean up Rubinius-compilied Ruby
  trash(dir('**/*.rbc'))
end

In fact, the Maid project uses Maid in its Rakefile.

You can also provide a custom description:

Maid::Rake::Task.new clean_torrents: [:dependency], description: 'Clean Torrents' do
  trash(dir('~/Downloads/*.torrent'))
end

Warranty

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.

License

GPLv2. See LICENSE for a copy.

More Repositories

1

moment-strftime

moment-strftime adds strftime and friends to Moment.js
JavaScript
55
star
2

TabCarousel

A Chrome extension to help you keep tabs on info you want to monitor. Great for a TV.
CoffeeScript
51
star
3

delayed-plugins-airbrake

delayed_job exception notification with airbrake
Ruby
36
star
4

maid-example

My personal Maid rules, as an example or source of inspiration for your own. :)
Ruby
21
star
5

markdo

Markdown-based task manager
Ruby
14
star
6

rubyconf2011

RubyConf 2011 Notes
12
star
7

utilities

Small command line programs I've written. Lots of good text filtering ones.
Ruby
12
star
8

homesick-vi-everywhere

A Homesick castle to use vi keybindings everywhere
Shell
6
star
9

node-haiku

Bindings for an evented language (Node.js) to an evented OS (Haiku, née OpenBeOS).
6
star
10

WunderlistConverter

Tools to convert Wunderlist backups to other formats
HTML
4
star
11

snippets

Stuff I write to test out ideas. Little programs that are worth keeping around.
Ruby
4
star
12

pencil_mustache

Need to replace some tokens? This is all you need (Ruby 1.9+). Just a few lines; no extra dependency needed.
Ruby
3
star
13

odin

An ATN-based parser for human languages, such as English.
Ruby
3
star
14

mjs

Minimal "Good Parts" JavaScript on the Rubinius VM
2
star
15

airplane_mode

No Internet? No problem! Use AirplaneMode to gather documentation for offline viewing.
Ruby
2
star
16

maid-mac

Mac OS X GUI for Maid
2
star
17

docco.vim

Syntax highlight Docco-style comments
Vim Script
2
star
18

politeness

Sometimes Rubyists can be a little rude. Require politeness.
Ruby
2
star
19

vertigo

Is the VerticalResponse API making you dizzy?
Ruby
2
star
20

vita

Vita: "vi in a textarea". In-browser vi-clone, targeting iOS (iPhone, iPad) and Chrome OS.
2
star
21

practice

Programming kata, etudes, etc.
CoffeeScript
1
star
22

EgoMonitor

Keep track of "scores" on sites you visit frequently, without having to check multiple pages, log in and out, etc.
JavaScript
1
star
23

alert

Easily add a little GUI interactivity to your Ruby and shell scripts.
Ruby
1
star
24

webm2vorbis

Extract Ogg Vorbis audio from a WebM file
Shell
1
star
25

conway.coffee

CoffeeScript implementation of Conway's Game of Life
CoffeeScript
1
star
26

post-to-jekyll

Post to a GitHub Pages-based Jekyll site without futzing with frontmatter
HTML
1
star
27

maid-gtk

GTK-based GUI for Maid for Linux, etc
1
star
28

roboconf

Like autoconf, but for Ruby projects
Shell
1
star
29

userscripts

Personal userscripts.
JavaScript
1
star
30

templates

Templates for various filetypes.
Ruby
1
star
31

railsconf2011

RailsConf 2011 Notes
1
star
32

asl-encyclopedia

Encyclopedia written in American Sign Language gloss.
HTML
1
star
33

continuity

A library for interacting with Ubuntu's Unity Web API
JavaScript
1
star
34

mhttpd

A simple C-based HTTP daemon (so I can practice C).
C
1
star
35

imap-openhack

Ruby
1
star
36

tt-rss

Tiny Tiny RSS on Heroku
PHP
1
star
37

www.benjaminoakes.com

My personal website
HTML
1
star
38

CrunchPipe

Ruby
1
star
39

raiden

A simple ATN parser for human languages, such as English.
Ruby
1
star
40

opal_example

Just a little example of compiling Opal to a single JavaScript file. Docker container and Guard included.
Ruby
1
star
41

temporary-text

Simple textarea for temporary text manipulation
HTML
1
star
42

bookmarklets

Bookmarklets for use on desktop and mobile
HTML
1
star
43

tiny-tiny-nas

Sideloaded NAS features for MIPS-based embedded Linux (tested with Actiontec C1000A router)
C
1
star