Advertisement
applehelpwriter

Eject Disks Advanced

Aug 3rd, 2016
861
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###########################################################
  2. # ABOUT
  3. ###########################################################
  4. (*
  5.  
  6.  Phil Stokes -- 2016
  7.  applehelpwriter.com
  8.  sqwarq.com
  9.  
  10. *)
  11. ###########################################################
  12. # DESCRIPTION
  13. ###########################################################
  14. (*
  15.  
  16. Choose which disks to eject, specify a group, and/or all from a list
  17.  
  18. *)
  19. ###########################################################
  20. # USAGE
  21. ###########################################################
  22. (*
  23.  
  24. Run the script and make a selection to eject.
  25.  
  26. *)
  27. ###########################################################
  28. # IMPORT STATEMENTS
  29. ###########################################################
  30.  
  31. use AppleScript version "2.4" -- Yosemite (10.10) or later
  32. use scripting additions
  33. ###########################################################
  34. # VARIABLES
  35. ###########################################################
  36.  
  37. set collection_1 to {}
  38. set diskList to {"All Disks"}
  39.  
  40.  
  41. --if you want to add a choice that groups some volumes together uncomment the following two lines:
  42. # set collection_1 to {"One vol", "Another vol", "Some other vol", "and so on vol"} -- supply the volunem names you want to group together here
  43. set diskList to {"All Disks", "Disk Group 1"}
  44.  
  45.  
  46. ###########################################################
  47. # COMMANDS
  48. ###########################################################
  49. tell application "Finder"
  50.     try
  51.         set diskList to diskList & (name of every disk whose ejectable is true)
  52.     on error
  53.         display dialog "No Disks are currently mounted" buttons {"OK"} default button "OK" with icon 1
  54.     end try
  55. end tell
  56.  
  57. if (count of diskList) is greater than 1 then
  58.     set theDisk to choose from list diskList with prompt "Select disks to eject:"
  59.     try
  60.         tell application "Finder"
  61.             if theDisk's item 1 is "All Disks" then
  62.                 eject every disk
  63.                
  64.             else if theDisk's item 1 is "Disk Group 1" then
  65.                 repeat with i from 1 to count of items in my collection_1
  66.                     set this_disk to item i of my collection_1
  67.                     eject (every disk whose name is this_disk)
  68.                 end repeat
  69.             else
  70.                 eject (every disk whose name is theDisk)
  71.             end if
  72.         end tell
  73.     end try
  74. end if
  75.  
  76. ###########################################################
  77. #EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement