MacOS – Ejecting all network drives via Applescript/Automator/Shell

applescriptautomationautomatormacos

I use the following script to attempt to eject all disks that aren't internal:

tell application "Finder"
    eject (disks whose ejectable is true)
end tell

This has the advantage of skipping volumes like MobileBackups as well as several others.

Unfortunately, it doesn't eject network shares.

Is there any way to get connected network shares in applescript?

As a +1, ideally this would skip things like optical disks as well.

EDIT: Both answers so far have shared ways to eject specific network disks. This, of course, is easy and I know how to do it. What I'm specifically asking for is a way to attempt to eject every disk other than system internal disks, regardless of their name.

Best Answer

I use Automator. I inserted 'Get Specified Finder Items', and named the target disks that I wanted to 'Get'. Only those named get chosen, but network drives do work. I then pipe this to 'Eject Disk'.

That's it.

enter image description here