Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

41 lines (36 sloc) 1.254 kb
#!/usr/bin/ruby
# Dropzone Destination Info
# Name: Drive[Un]Mount
# Description: Mounts or unmounts all USB and FireWire drives connected to the system
# Handles: NSStringPboardType
# Creator: Brett Terpstra (modified by Ian Soper http://iansoper.com)
# URL: http://brettterpstra.com
# IconURL: http://brettterpstra.com/destinations/icons/fwmounter.png
# Events: Clicked
def clicked
$dz.begin("Scanning for drives")
$dz.determinate(false)
profdata = `system_profiler SPFireWireDataType SPUSBDataType`
disks = profdata.scan(/BSD Name: (disk.$)/)
mounted = false
profdata.scan(/Mount Point: ([^\n]+)/).each { |mounted|
mounted = mounted[0].empty? ? false : true
break if mounted == true
}
if mounted == true
message = "Cancelled"
res = `./CocoaDialog yesno-msgbox --title "Disks Mounted" --text "Unmount all USB & FireWire drives?" --informative-text "At least one USB or FireWire volume is mounted, do you want to unmount ALL of them?"`
disks.each {|disk|
`/usr/sbin/diskutil unmountDisk #{disk}`
message = "Unmounted"
} if res.to_i == 1
$dz.finish(message)
else
# need a confirmation dialog?
disks.each {|disk|
`/usr/sbin/diskutil mountDisk #{disk}`
}
$dz.finish("Mounted")
end
$dz.url(false)
end
Jump to Line
Something went wrong with that request. Please try again.