-
Notifications
You must be signed in to change notification settings - Fork 49
/
FWMount.dropzone
40 lines (36 loc) · 1.13 KB
/
FWMount.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: FW[Un]Mount
# Description: Mounts or unmounts all FW drives connected to the system
# Handles: NSStringPboardType
# Creator: Brett Terpstra
# 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`
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 FireWire drives?" --informative-text "At least one FW 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