Skip to content

Instantly share code, notes, and snippets.

@bobthecow bobthecow/rules.rb
Last active Dec 9, 2015

Embed
What would you like to do?
Maid rules
# https://github.com/benjaminoakes/maid
Maid.rules do
## Trash a bunch of downloaded stuffs ##
rule 'Trash duplicate downloads' do
# Keep the dupe with the shortest filename
trash verbose_dupes_in('~/Downloads/*')
end
rule 'Trash development downloads' do
files('~/Downloads/*').each do |path|
if downloaded_from(path).any? { |u| u.match %r{//(localhost|[^\.]+\.dev)} } and 1.week.since? accessed_at path
trash path
end
end
end
rule 'Trash zips and tarballs downloaded from GitHub' do
dir('~/Downloads/*.{zip,tgz,gz,rar,tar}').each do |path|
if downloaded_from(path).any? { |u| u.match %r{//([^\/]+\.)?github\.com\/} }
trash path
end
end
end
rule 'Trash incomplete downloads' do
trash dir('~/Downloads/*.download').select { |p| 30.days.since modified_at p }
end
## Save some downloaded stuffs ##
rule 'Add downloaded music to iTunes' do
move dir('~/Downloads/*.mp3').select { |p| duration_s(p) > 45.0 }, '~/Music/iTunes/Automatically Add to iTunes/'
end
rule 'Archive downloaded applications in zip files' do
dir('~/Downloads/*.zip').each do |path|
if zipfile_contents(path).any? { |c| c.match %r{\.app$} }
move path, '~/Downloads/Applications'
end
end
end
# And organize the rest
DOWNLOAD_TYPES = {
'Applications' => ['public.disk-image', 'com.apple.application', 'com.apple.installer-package-archive'],
'Archives' => 'public.archive',
'Audio' => 'public.audio',
'Images' => 'public.image',
'PDFs' => 'com.adobe.pdf',
'Video' => 'public.movie',
}
DOWNLOAD_TYPES.each do |sub_dir, types|
rule "Move downloaded #{sub_dir.downcase}" do
move where_content_type(dir('~/Downloads/*.*'), types), mkdir("~/Downloads/#{sub_dir}")
end
end
## Desktop cleanup ##
rule 'Archive old screenshots on the Desktop' do
move dir('~/Desktop/Screen Shot *').select { |p| 2.days.since? accessed_at p }, mkdir('~/Documents/Screenshots/')
end
rule 'Archive old links on the Desktop' do
move dir('~/Desktop/*.webloc').select { |p| 7.days.since? created_at p }, mkdir('~/Desktop/Links')
end
rule 'Remove empty directories' do
dir(['~/Desktop/*', '~/Downloads/*']).each do |path|
if File.directory?(path) && dir("#{ path }/*").empty?
trash(path)
end
end
end
end
@benjaminoakes

This comment has been minimized.

Copy link

commented Dec 17, 2012

I'm really impressed with your gist. You've implemented some features I'd love to bring into Maid itself (e.g. list duplicate files) and I also like your files method.

Would you be willing to contribute this code? (By making a pull request if possible.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.