osx-trash 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/COPYING +21 -0
- data/README +44 -0
- data/Rakefile +60 -0
- data/bin/trash +147 -0
- data/lib/osxtrash/version.rb +3 -0
- metadata +58 -0
data/COPYING
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
Copyright (c) 2008 Dave Dribin
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use, copy,
|
7
|
+
modify, merge, publish, distribute, sublicense, and/or sell copies
|
8
|
+
of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
18
|
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
19
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
= Overview
|
2
|
+
|
3
|
+
osx-trash is a command line program called trash[link:files/bin/trash.html]
|
4
|
+
to manipulate the trash on Mac OS X. It uses AppleScript via Scripting Bridge
|
5
|
+
on top of RubyCocoa to manipulate the trash, just like the Finder does. Here's
|
6
|
+
a simple example:
|
7
|
+
|
8
|
+
% touch foo bar baz
|
9
|
+
% trash -l
|
10
|
+
% trash foo ba*
|
11
|
+
% trash -l
|
12
|
+
/Users/dave/.Trash/foo
|
13
|
+
/Users/dave/.Trash/bar
|
14
|
+
/Users/dave/.Trash/baz
|
15
|
+
% trash -e
|
16
|
+
% trash -l
|
17
|
+
|
18
|
+
Using Finder's AppleScript has a number of benefits compared to shell scripts
|
19
|
+
that just move files to ~/.Trash. First, it creates unique names when there
|
20
|
+
are collisions:
|
21
|
+
|
22
|
+
% touch foo
|
23
|
+
% trash foo
|
24
|
+
% touch foo
|
25
|
+
% trash foo
|
26
|
+
% trash -l
|
27
|
+
/Users/dave/.Trash/foo
|
28
|
+
/Users/dave/.Trash/foo 20-38-20
|
29
|
+
|
30
|
+
It also handles trashes on different volumes properly:
|
31
|
+
|
32
|
+
% touch foo
|
33
|
+
% trash foo
|
34
|
+
% touch /Volumes/DiskImage/bar
|
35
|
+
% trash /Volumes/DiskImage/bar
|
36
|
+
% trash -l
|
37
|
+
/Users/dave/.Trash/foo
|
38
|
+
/Volumes/DiskImage/.Trashes/501/bar
|
39
|
+
|
40
|
+
= Links
|
41
|
+
|
42
|
+
* Project page: http://www.dribin.org/dave/osx-trash/
|
43
|
+
* RubyForge project: http://rubyforge.org/projects/osx-trash/
|
44
|
+
* Online documentation: http://osx-trash.rubyforge.org/api/
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/gempackagetask'
|
6
|
+
|
7
|
+
$LOAD_PATH.unshift 'lib'
|
8
|
+
require 'osxtrash/version'
|
9
|
+
|
10
|
+
$KCODE = "UTF-8"
|
11
|
+
|
12
|
+
task :default => [:test_units]
|
13
|
+
|
14
|
+
desc "Run basic tests"
|
15
|
+
Rake::TestTask.new("test_units") do |t|
|
16
|
+
t.pattern = 'test/*_test.rb'
|
17
|
+
t.verbose = false
|
18
|
+
t.warning = true
|
19
|
+
end
|
20
|
+
|
21
|
+
PKG_NAME = 'osx-trash'
|
22
|
+
PKG_VERSION = OSXTrash::VERSION
|
23
|
+
PKG_FILES = FileList[
|
24
|
+
'[A-Z]*',
|
25
|
+
'bin/**/*',
|
26
|
+
'lib/**/*.rb',
|
27
|
+
]
|
28
|
+
|
29
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
30
|
+
rdoc.rdoc_dir = 'rdoc'
|
31
|
+
rdoc.title = "#{PKG_NAME} -- Mac OS X Trash Manipulation"
|
32
|
+
rdoc.rdoc_files.include('README')
|
33
|
+
rdoc.rdoc_files.include('bin/*')
|
34
|
+
end
|
35
|
+
|
36
|
+
spec = Gem::Specification.new do |s|
|
37
|
+
s.platform = Gem::Platform::RUBY
|
38
|
+
s.summary = "Mac OS X Trash Manipulation"
|
39
|
+
s.name = PKG_NAME
|
40
|
+
s.version = PKG_VERSION
|
41
|
+
s.requirements << 'Mac OS X 10.5'
|
42
|
+
s.requirements << 'RubyCocoa'
|
43
|
+
s.require_path = 'lib'
|
44
|
+
s.files = PKG_FILES
|
45
|
+
s.has_rdoc = true
|
46
|
+
s.bindir = 'bin'
|
47
|
+
s.executables = ['trash']
|
48
|
+
s.description = <<-EOF
|
49
|
+
Manipulate the Mac OS X Finder's Trash using Scripting Bridge and RubyCocoa.
|
50
|
+
EOF
|
51
|
+
|
52
|
+
s.author = "Dave Dribin"
|
53
|
+
s.homepage = "http://www.dribin.org/dave/osx-trash/"
|
54
|
+
s.rubyforge_project = 'osx-trash'
|
55
|
+
end
|
56
|
+
|
57
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
58
|
+
pkg.need_zip = true
|
59
|
+
pkg.need_tar = true
|
60
|
+
end
|
data/bin/trash
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# == Synopsis
|
4
|
+
#
|
5
|
+
# Manipulate the Mac OS X trash
|
6
|
+
#
|
7
|
+
# == Usage
|
8
|
+
#
|
9
|
+
# trash [OPTIONS] <file> [<file> ...]
|
10
|
+
# trash [OPTIONS] [-e | --empty]
|
11
|
+
# trash [OPTIONS] [-l | --list]
|
12
|
+
#
|
13
|
+
# == Options
|
14
|
+
#
|
15
|
+
# -e, --empty:: Empty the trash.
|
16
|
+
#
|
17
|
+
# -l, --list:: List items in the trash.
|
18
|
+
#
|
19
|
+
# -h, --help:: Prints a help message and exits.
|
20
|
+
#
|
21
|
+
# -v, --version:: Prints the version and exits.
|
22
|
+
#
|
23
|
+
# == Author
|
24
|
+
# Dave Dribin
|
25
|
+
#
|
26
|
+
# == Copyright
|
27
|
+
# Copyright (c) 2008 Dave Dribin
|
28
|
+
# Licensed under the MIT license.
|
29
|
+
|
30
|
+
require 'pathname'
|
31
|
+
require 'optparse'
|
32
|
+
require 'ostruct'
|
33
|
+
require 'osxtrash/version'
|
34
|
+
|
35
|
+
require 'osx/cocoa'
|
36
|
+
include OSX
|
37
|
+
OSX.require_framework 'ScriptingBridge'
|
38
|
+
|
39
|
+
class OSXTrashApp
|
40
|
+
COMMAND = File.basename($0)
|
41
|
+
USAGE =<<EOF
|
42
|
+
Usage: #{COMMAND} [OPTIONS] <file> [<file> ...]
|
43
|
+
#{COMMAND} [-e | --empty]
|
44
|
+
#{COMMAND} [-l | --list]
|
45
|
+
EOF
|
46
|
+
|
47
|
+
def initialize
|
48
|
+
@options = OpenStruct.new
|
49
|
+
@options.empty = false
|
50
|
+
@options.list = false
|
51
|
+
end
|
52
|
+
|
53
|
+
def create_finder
|
54
|
+
stderr = $stderr.clone # save current STDERR IO instance
|
55
|
+
$stderr.reopen('/dev/null', 'w') # send STDERR to /dev/null
|
56
|
+
finder = SBApplication.applicationWithBundleIdentifier("com.apple.Finder")
|
57
|
+
$stderr.reopen(stderr) # revert to default behavior
|
58
|
+
return finder
|
59
|
+
end
|
60
|
+
|
61
|
+
def run(argv)
|
62
|
+
exit_code = 0
|
63
|
+
begin
|
64
|
+
if parse_options(argv)
|
65
|
+
exit_code = main(argv)
|
66
|
+
end
|
67
|
+
rescue
|
68
|
+
STDERR.puts "#{COMMAND}: " + $!
|
69
|
+
exit_code = 1
|
70
|
+
end
|
71
|
+
return exit_code
|
72
|
+
end
|
73
|
+
|
74
|
+
def parse_options(argv)
|
75
|
+
opts = OptionParser.new do |opts|
|
76
|
+
opts.banner = USAGE
|
77
|
+
opts.separator ""
|
78
|
+
opts.separator "Specific options:"
|
79
|
+
|
80
|
+
opts.on("-e", "--empty", "Empty the trash") do
|
81
|
+
@options.empty = true
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on("-l", "--list", "List items in the trash") do
|
85
|
+
@options.list = true
|
86
|
+
end
|
87
|
+
|
88
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
89
|
+
puts opts
|
90
|
+
puts
|
91
|
+
puts "Manipulate to the Finder's trash."
|
92
|
+
return false
|
93
|
+
end
|
94
|
+
|
95
|
+
opts.on_tail("-v", "--version", "Show version") do
|
96
|
+
puts "#{COMMAND} #{OSXTrash::VERSION}"
|
97
|
+
return false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
opts.parse!(argv)
|
102
|
+
return true
|
103
|
+
end
|
104
|
+
|
105
|
+
def main(argv)
|
106
|
+
if (@options.empty)
|
107
|
+
finder = create_finder
|
108
|
+
trash = finder.trash
|
109
|
+
trash.warnsBeforeEmptying = false
|
110
|
+
trash.emptySecurity(false)
|
111
|
+
return 0
|
112
|
+
end
|
113
|
+
|
114
|
+
if (@options.list)
|
115
|
+
finder = create_finder
|
116
|
+
trash = finder.trash
|
117
|
+
trash.items.each do |item|
|
118
|
+
file_url = NSURL.URLWithString(item.URL)
|
119
|
+
Pathname item_path = Pathname.new(file_url.path)
|
120
|
+
puts item_path
|
121
|
+
end
|
122
|
+
return 0
|
123
|
+
end
|
124
|
+
|
125
|
+
files = ARGV
|
126
|
+
if (files.length == 0)
|
127
|
+
$stderr.puts USAGE
|
128
|
+
$stderr.puts "Try `#{COMMAND} --help' for more information."
|
129
|
+
return 1
|
130
|
+
end
|
131
|
+
|
132
|
+
finder = create_finder
|
133
|
+
files.each do |file|
|
134
|
+
path = Pathname.new(file)
|
135
|
+
url = NSURL.fileURLWithPath(path.realpath.to_s)
|
136
|
+
item = finder.items.objectAtLocation(url)
|
137
|
+
item.delete
|
138
|
+
end
|
139
|
+
return 0
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
app = OSXTrashApp.new
|
144
|
+
rc = app.run(ARGV)
|
145
|
+
exit rc
|
146
|
+
|
147
|
+
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: osx-trash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dave Dribin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-05-24 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Manipulate the Mac OS X Finder's Trash using Scripting Bridge and RubyCocoa.
|
17
|
+
email:
|
18
|
+
executables:
|
19
|
+
- trash
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- COPYING
|
26
|
+
- Rakefile
|
27
|
+
- README
|
28
|
+
- bin/trash
|
29
|
+
- lib/osxtrash/version.rb
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://www.dribin.org/dave/osx-trash/
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: "0"
|
42
|
+
version:
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: "0"
|
48
|
+
version:
|
49
|
+
requirements:
|
50
|
+
- Mac OS X 10.5
|
51
|
+
- RubyCocoa
|
52
|
+
rubyforge_project: osx-trash
|
53
|
+
rubygems_version: 1.0.1
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: Mac OS X Trash Manipulation
|
57
|
+
test_files: []
|
58
|
+
|