Created
April 26, 2013 07:21
-
-
Save chsh/5465517 to your computer and use it in GitHub Desktop.
Volume unmount utility for Mac OS X.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class Runner | |
attr_reader :args | |
def initialize(args) | |
@args = args | |
end | |
def run | |
targets = targets_by_args %w(/Volumes/Name1 /Volumes/Name2 /Volumes/Name3) | |
disks = pick_disks targets | |
umount_disks disks | |
end | |
private | |
def pick_disks(*names) | |
names = [names].flatten | |
lines = `df`.chomp.split(/\r?\n/) | |
disks = [] | |
names.each do |name| | |
lines.each do |line| | |
if line.index name | |
disks << line.split(/\s+/)[0] | |
end | |
end | |
end | |
disks | |
end | |
def targets_by_args(*names) | |
names = [names].flatten | |
return names if @args.size == 0 | |
targets = [] | |
@args.each do |arg| | |
da = arg.downcase | |
names.each do |name| | |
if name.downcase.index(da) | |
targets << name | |
end | |
end | |
end | |
targets | |
end | |
def umount_disks(disks) | |
disks.each do |disk| | |
cmd = "diskutil umount #{disk}" | |
puts cmd | |
`#{cmd}` | |
end | |
end | |
end | |
Runner.new(ARGV).run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment