Eject all disks except for

I like how simple the eject all disks code can be:

try
tell application "Finder"
eject the disks
end try

I would love it if there was a way to add an exception to the list instead of having to manually list all the drives I do want to eject. Specifically, I'm looking for a way to eject all external drives except for my time machine drive. Is there a way to add an applescript exception to the code to allow this?

1 Like

You might want to consider the app mentioned here:

It appears to have the option to exempt drives from ejection.

Check out MACROS: Mount Drive, Unmount Drive, Check if Drive is Mounted for some good pointers.

I checked it out but doesn't quite offer the functionality that I want. I want to always leave a specific drive mounted and mount all other drives which that doesn't help me with. The name of the drive will be the same every time, I just figured someone who knew applescript would be able to tell me how to add an exception to it.

Are you sure you want to eject all other disks? For example, one of my ejectable disks is "Macintosh HD - Data." You can check yours like this:

tell application "Finder"
	return the disks whose ejectable is true
end tell

If you do just want to modify the script in your post to exclude one known disc, try this:

try
	tell application "Finder"
		eject (the disks whose name is not "<name of disk to exclude here>")
	end tell
end try

Hello :wave:

You can control Jettison based on your conditions on mounting or unmounting using AppleScript with System Events …

If you put your Mac to sleep Jettison will unmount the drives for you and remount them on wake - maybe I am wrong here but I think there is a possibility that only the ones you’ve had mounted before sleepmode will get mounted again after wake and not the others that you don’t need … but even that is not the case … use AppleScript to unmount the ones you don’t need or change the behavior completely or even to other drives …

Greetings from Germany

Tobias

1 Like

This is perfect! Thank you so much!!

1 Like

Hey @triplesgames :wave:

My friend told me that Jettison has AppleScript support so you could talk directly to the Application using these 4 commands:


tell application "Jettison" to Mount <DriveName>

tell application "Jettison" to Eject <DriveName>

tell application "Jettison" to EjectAndSleep

tell application "Jettison" to Sleep 

  • the Mount command mounts all previously ejected drives or the ones you define

  • the Eject command ejects all drives or the ones you define

  • the EjectAndSleep command ejects all drives and puts the Mac directly to sleep

  • the Sleep command puts the Mac to sleep

Using these commands you can also have the full control over diskimages (dmg) and sd cards if you want - for this to work you have to enable the corresponding Settings…

This application is a game changer no more unnecessary unplugging and replugging for drives or the usage of diskutil to mount a drive …

Greetings from Germany

Tobias

1 Like