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

eject partition

I am trying to eject partitions from my desktop if they exist. The following automator script does not execute reliably. Running as an AppleScript in Automator. It may eject 1 or 2 partitions and leave the third or if there are 2 mounted, it may just eject 1. Appreciate any help in reliably unmounting these partitions. Or any different way.


on run {input, parameters}
	
	tell application "Finder"
		if exists disk "A" then
			eject disk "A"
		end if
		
	end tell
	
	tell application "Finder"
		if exists disk "B" then
			eject disk "B"
		end if
		
	end tell
	
	tell application "Finder"
		if exists disk "C" then
			eject disk "C"
		end if
		
	end tell
	
	return input
end run

iMac Line (2012 and Later)

Posted on Jan 30, 2022 11:43 PM

Reply
Question marked as Best reply

Posted on Jan 31, 2022 12:51 PM

Hard to tell without seeing it work (or fail), but my guess would be a race condition. Ejecting a volume takes a second or two while the OS cleans up the disk caches, etc. It could be that the Finder blocks other actions (e.g. unmounting the second volume) while the previous one is still in process. Sure, it shouldn't do that, but, hey... real world.


If that theory is correct then the simplest fix would be to add some delay after ejecting one volume, before checking the next.


If that theory isn't correct then you probably need to add some logging to gather diagnostic data - such as what drives does the script see when it starts? does it think it ejected them?

4 replies
Question marked as Best reply

Jan 31, 2022 12:51 PM in response to APPLEAL

Hard to tell without seeing it work (or fail), but my guess would be a race condition. Ejecting a volume takes a second or two while the OS cleans up the disk caches, etc. It could be that the Finder blocks other actions (e.g. unmounting the second volume) while the previous one is still in process. Sure, it shouldn't do that, but, hey... real world.


If that theory is correct then the simplest fix would be to add some delay after ejecting one volume, before checking the next.


If that theory isn't correct then you probably need to add some logging to gather diagnostic data - such as what drives does the script see when it starts? does it think it ejected them?

Feb 1, 2022 6:46 PM in response to APPLEAL

If you are connecting a drive with multiple volumes, but you don't want all those volumes to be automatically mounted, then I would explore configuring "fstab" to not automatically mount those volumes by referencing the UUIDs of those volumes. I'm not entirely certain how the "fstab" file should be configured for macOS as it differs significantly from what I'm familiar with when using Linux. I do know that macOS mentions that a special command should be used to open the command line editor for editing the "fstab" file safely. Any example I would give would be a best guess with no idea if it would be correct or even ideal.


Sometimes you should actually post a little more detail about the big picture instead of the final result you wish to have. If I'm correct, then to me it is much better never to mount the volume than have the Mac tied up mounting (or even attempting to mount) multiple volumes, then immediately unmounting them. If you have a drive with multiple volumes and you only want certain ones to be automatically mounted, then "ejecting" is probably not what you want as "ejecting" usually ejects all the volumes on that drive. "Unmounting" and "ejecting" are two similar though slightly different things (unless automator or applescript is different in terminology -- I'm not real familiar with either one).

eject partition

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