luke0x (owner)

Forks

Revisions

gist: 136569 Download_button fork
public
Public Clone URL: git://gist.github.com/136569.git
Text only
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
drefile: an automatic, chronological file organizer
---------------------------------------------------
Every few minutes drefile copies all files on your Desktop to a folder
such as ~/Documents/2009-06-June/26-Friday, prepending a timestamp
(like 20090626.1310) to the filename.
 
Use
---
1. Put files on your Desktop, and in a few minutes they will be 'drefiled'
2. Use the 'Today' alias on your Desktop to go to today's folder
3. Type 'dday' to go to today's directory
4. Type 'dmonth' to go to this month's directory
5. Type 'drefile file' to manually timestamp + move a file
 
Install
-------
1. sudo port install osxutils
2. sudo gem install open4
3. copy the 3 files below to ~/.bin (or whatever, in the path)
4. chmod +x the 3 files
5. crontab -e this: 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /Users/luke/.bin/drefile >>
/Users/luke/.bin/drefile_cron.log
 
dday.rb
-------
#!/usr/bin/env ruby
 
require "fileutils"
 
month_and_day = Time.now.strftime("%Y-%m-%B/%d-%A")
dir = "/Users/luke/Documents/#{month_and_day}"
FileUtils.mkdir_p dir
puts "cd #{dir}"
 
dmonth.rb
---------
#!/usr/bin/env ruby
 
require "fileutils"
 
month = Time.now.strftime("%Y-%m-%B")
dir = "/Users/luke/Documents/#{month}"
FileUtils.mkdir_p dir
puts "cd #{dir}"
 
drefile
-------
#!/usr/bin/env ruby
 
# desktop refile
# requires mkalias from the osxutils port
# cron to run every 5 minutes
# 0,5,10,15,20,25,30,35,40,45,50,55 * * * * /Users/luke/.bin/drefile.rb >> /Users/luke/.bin/drefile_cron.log
 
HOME_DIRECTORY = "/Users/luke"
 
DESKTOP_DIRECTORY = "#{HOME_DIRECTORY}/Desktop"
STORAGE_DIRECTORY = "#{HOME_DIRECTORY}/Documents"
LOG_DIRECTORY = "#{HOME_DIRECTORY}/.bin"
SHELL = "/bin/bash"
 
require 'rubygems'
require 'open4'
require 'logger'
require "fileutils"
require 'time'
 
if ARGV.length == 0
  # make the drefile dir
  month_and_day = Time.now.strftime("%Y-%m-%B/%d-%A")
  drefile_directory = "#{STORAGE_DIRECTORY}/#{month_and_day}"
  FileUtils.mkdir_p(drefile_directory)
  timestamp_prefix = Time.now.strftime("%Y%m%d.%H%M")
 
  # remove the today alias
  FileUtils.rm("#{DESKTOP_DIRECTORY}/Today") if File.exists?("#{DESKTOP_DIRECTORY}/Today")
 
  # move files with a datetime prefix
  Dir.entries(DESKTOP_DIRECTORY).reject{|f| f =~ /^\./}.each do |file_name|
    FileUtils.mv("#{DESKTOP_DIRECTORY}/#{file_name}", "#{drefile_directory}/#{timestamp_prefix} #{file_name}")
  end
 
  # remake the today alias
  `/opt/local/bin/mkalias -r "#{drefile_directory}" "#{HOME_DIRECTORY}/Desktop/Today"`
else
  # make the drefile dir
  timestamp = Time.parse(Open4.open4("mdls -name kMDItemFSCreationDate -raw #{ARGV.first}")[2].read)
  drefile_directory = "#{STORAGE_DIRECTORY}/#{timestamp.strftime("%Y-%m-%B/%d-%A")}"
  FileUtils.mkdir_p(drefile_directory)
 
  new_file = "#{drefile_directory}/#{timestamp.strftime("%Y%m%d.%H%M")} #{ARGV.first}"
  FileUtils.mv(ARGV.first, new_file)
  puts new_file
end
Text only