You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Automatically eject all partitions-Catalina

Is there an AppleScript/Automator way to automatically eject all partitions of an external drive after being attached to a mac. Ideally, I would like to plug in the drive and walk away and the process would start, and would find none of the partitions mounted after a certain period of time.

Thanks

iMac Line (2012 and Later)

Posted on Feb 17, 2020 3:21 PM

Reply
Question marked as Top-ranking reply

Posted on Feb 18, 2020 11:05 PM

> I didn't want to wait for them to mount and then delete.


You can't do that via AppleScript.


Any AppleScript can only take place after the drive has already been mounted.


If you want to prevent the volumes from mounting in the first place, you likely need to get 'under the hood' and probably play with something like /etc/fstab to tell the mount subsystem to not automatically mount the volume(s).


Something like:


UUID=ABCDEF01-79F7-33FF-BE85-E1D3ABD3EDEA none hfs rw,noauto


Where the first field lists the UUID of the volume in question - you can get this via diskutil info in Terminal.app. The middle two fields are largely irrelevant in this case, but the 'rw, noauto' at the end indicates it's a read/write device, but not to automount the volume.


There is no GUI approach to managing this that I'm aware of.

Similar questions

4 replies
Question marked as Top-ranking reply

Feb 18, 2020 11:05 PM in response to mrokloricred37

> I didn't want to wait for them to mount and then delete.


You can't do that via AppleScript.


Any AppleScript can only take place after the drive has already been mounted.


If you want to prevent the volumes from mounting in the first place, you likely need to get 'under the hood' and probably play with something like /etc/fstab to tell the mount subsystem to not automatically mount the volume(s).


Something like:


UUID=ABCDEF01-79F7-33FF-BE85-E1D3ABD3EDEA none hfs rw,noauto


Where the first field lists the UUID of the volume in question - you can get this via diskutil info in Terminal.app. The middle two fields are largely irrelevant in this case, but the 'rw, noauto' at the end indicates it's a read/write device, but not to automount the volume.


There is no GUI approach to managing this that I'm aware of.

Feb 18, 2020 5:32 AM in response to mrokloricred37

AppleScript will allow you to determine, or exclude, locally (USB) mounted, or NAS mounted drives, and then eject them.


-- in this example, "T M" is the name of the Time Machine drive which is not to be ejected
set excluded to {"home", "net", "T M"}

tell application "Finder"
	set alist to (every disk whose ejectable is true or local volume is false and excluded does not contain its name)
	log alist
	(*
	repeat with adrive in alist
		eject adrive
	end repeat
	*)
end tell


I have excluded my Time Machine drive in the above example. Otherwise, a mounted USB SSD, and a Synology NAS network share mounted to my Desktop are detected, and ejected. There is an AppleScript block comment around the ejection repeat block in the above code, because the first time the code is run, you should determine what the list alist contains for your usage.


Launch the Script Editor from Dock : Launchpad : Other : Script Editor. On the bottom of the Script Editor, you will see three icons:



Click the right-most icon, and this will open a display area whose heading will be Result, Messages, Events, and Replies. By clicking Replies, you can see the results of the AppleScript running and log command output.


Copy and paste the above AppleScript into the Script Editor, Click the hammer (compile) button, and then the run button. It is likely that when you uncomment the repeat block that you will see error number 0 following each eject. This is normal.




Feb 17, 2020 9:34 PM in response to mrokloricred37

APPLEAL wrote:

Is there an AppleScript/Automator way to automatically eject all partitions of an external drive after being attached to a mac. Ideally, I would like to plug in the drive and walk away and the process would start, and would find none of the partitions mounted after a certain period of time.
Thanks



Well, I do know if you hold the option key when ejecting—it unmounts all partitions.

Feb 18, 2020 1:49 PM in response to VikingOSX

I hope I made myself clear. I have a drive with 4 partitions, call them a,b,c,TM (WHERE TM IS A TIME MACHINE VOLUME). I want to plug in my usb external drive with these partitions, and have ALL of the partitions ejected automatically. I want to use them at a later time. I didn't want to wait for them to mount and then delete. Perhaps asking too much ?

Thanks

Automatically eject all partitions-Catalina

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.