Project

filesortd

0.01
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Automatic rule-based sorting for your files. Like Hazel, but doesn't need a GUI.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 0
>= 0
>= 0
>= 0
 Project Readme

Filesortd Build Status

A Ruby DSL for automatically sorting your files based on rules. Like Hazel, but cross-platform, no GUI required.

Installation

$ gem install filesortd

If you're on OS X, also install osx-plist for things like downloaded_from (i.e. xattr support) to work:

$ gem install osx-plist

Usage

$ filesortd start yourconfig.rb

yourconfig.rb:

### This works everywhere:
folder "/Users/myfreeweb/Downloads" do
  # Using a single matcher
  pattern "*.mp3" do
    mv "/Users/myfreeweb/Music"

    # Do things if running on a particular OS
    os :linux do
      mv "/opt/music"
    end

    # Note that actions like `mv` update the location, so you can use them multiple times
  end

  # Using multiple matchers
  match pattern: "*.psd", pattern: %r{doc[1-2]+} do
    rm
  end
end

### This only works on Mac OS X
os :osx do
  folder "/Users/myfreeweb/Downloads" do
    downloaded_from %r{destroyallsoftware} do
      mv "/Users/myfreeweb/Movies/DAS"
      open_in :default
      # or
      open_in "MPlayerX"
    end

    kind "Ruby Source" do
      label :red
    end

    label :green do
      mv "/Users/myfreeweb/Documents"
      applescript 'tell app "Finder" to reveal theFile'
    end

    # This is the multiple matcher syntax
    match pattern: '*.mp4', downloaded_from: %r{destroyallsoftware} do
      label :gray
    end
  end
end

### You can watch multiple folders at once
folders "/Users/myfreeweb/Pictures", "/opt/pictures" do
  # Do things to any files
  any do
    label :blue
  end

  # Match by extension -- same as pattern "*.png"
  ext :png do
    pass "optipng"
    label :green
  end
end

Matchers

  • any -- any file
  • pattern(pat) -- files that conform to pat (regexp or glob)
  • ext(extn) (or extension) -- files that have an extension of extn
  • kind(knd) -- files that have Spotlight kind of knd
  • label(lbl) -- files that have Finder label of lbl
  • downloaded_from(url) -- files that were downloaded from url matching url

Matchers can be called either by themselves

label :gray do
  kind 'Ruby Source' do
  end
end

or grouped into a single statement (preferred)

match label: :gray, kind: 'Ruby Source' do
end

in Ruby 1.8:

match :label => :gray, :kind => 'Ruby Source' do
end

Actions

  • contents (or read) -- get the contents
  • rm (or remove, delete, unlink) -- remove
  • trash -- put to trash (OS X/Linux, Linux requires trash-cli)
  • cp (or copy) -- copy
  • mv (or move) -- move/rename
  • pipe(cmd) -- start the command, pass the file to stdin, get the stdout
  • pass(cmd) -- start the command, pass the path to the file as an argument, get the stdout
  • label(color) -- set the OS X Finder label (:none, :orange, :red, :yellow, :blue, :purple, :green, :gray or :grey)
  • open_in(app) -- open the file using the OS X open command, use :default for the default app for the file type
  • applescript(script) -- run provided AppleScript. Use theFile inside it to refer to the file matched

Contributors

License

MIT.