Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- ABOUT
- script by Phil Stokes (c)2014
- applehelpwriter.com
- HOW TO USE
- --run the script as is to eject all and only disk images (i.e. eject .dmg but not hard disks)
- --to make the script eject all external disks EXCEPT dmgs, look at the function near the end of the script called 'on compareAndEject(listDmgs, listDisks)'. In this function, replace the line:
- if i is in listDmgs then
- with the line:
- if i is not in listDmgs then
- *)
- getEveryDisk()
- set diskList to the result
- set origDeLims to AppleScript's text item delimiters
- set AppleScript's text item delimiters to return
- set myDMGNames to {}
- set x to {}
- try
- set x to (do shell script "hdiutil info | grep '/dev'") as text
- end try
- set AppleScript's text item delimiters to origDeLims
- if x is not equal to {} then
- repeat with i from 1 to count of paragraphs in x
- set z to getDMGName(paragraph i in x)
- set end of myDMGNames to z
- end repeat
- compareAndEject(myDMGNames, diskList)
- else
- #comment out the next line and remove the hash for the subsequent line if OS is <10.9
- display notification "No mounted disk images!"
- #display dialog "No mounted disk images!"
- end if
- on getEveryDisk()
- set origDeLims to AppleScript's text item delimiters
- set AppleScript's text item delimiters to "/"
- set allMounts to do shell script "diskutil list | grep /dev"
- set allMounts to result as string
- set allMounts to allMounts as text
- set AppleScript's text item delimiters to origDeLims
- set diskList to {}
- repeat with i from 1 to count of paragraphs in allMounts
- set the end of diskList to (allMounts's paragraph i)
- end repeat
- return diskList
- end getEveryDisk
- on getDMGName(aParagraph)
- set a to items 1 thru 13 in aParagraph as list
- set numList to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
- repeat
- if numList contains last item of a then
- exit repeat
- else
- set b to the reverse of a
- set a to the rest of b
- set a to the reverse of a
- end if
- end repeat
- set a to a as string
- return a
- end getDMGName
- on compareAndEject(listDmgs, listDisks)
- try
- repeat with i in listDisks
- if i is in listDmgs then
- try
- do shell script "diskutil unmountDisk " & i
- end try
- end if
- end repeat
- end try
- end compareAndEject
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement