Macotron

macotron.disks

List the volumes that Finder shows, with their size and free space, and eject a disk.

// Put an eject item in the menu bar for each external disk.
const menu = macotron.disks.list()
  .filter((v) => v.ejectable)
  .map((v) => ({
    title: "Eject " + v.name,
    onClick: async () => {
      const r = await macotron.disks.eject(v.path);
      if (!r.ok) macotron.notify.toast("Could not eject " + v.name, r.error, { color: "error" });
    },
  }));
macotron.menubar.status("eject", { sfSymbol: "eject.fill", menu });

Listing

list(): Array<{ name, path, device, fsType, total, free, available, internal, removable, ejectable, network, readOnly, root }>

The mounted volumes that Finder shows. System volumes that Finder hides, such as /System/Volumes/Data, are not in the list. The startup disk is the row with root: true and path: "/".

The call does not wait for a server. Macotron reads the sizes of a network share from the kernel's last reading, so they can be out of date, and the call cannot stop when a server is gone.

Ejecting

eject(path): Promise<{ ok, error? }>

Unmounts every volume on the disk that holds path, then ejects the disk. When an app keeps a file open on the volume, ok is false and error tells why.

See also