forked from a4agarwal/dropzone-user-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriveMount.dropzone
40 lines (36 loc) · 1.22 KB
/
DriveMount.dropzone
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
#!/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