On Mac OS with python how to list only writable volumes? In other words, in the /Volumes folder I want to list only the (partitions and pendrives) rw I don't want to list CDROM drives or mounted ISO images.
In linux there is the file '/proc/mounts' which displays the mounted drives with the type of partition and the mount options, in mac OS is there something similar? In linux I use it like this:
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
from pathlib import Path
import getpass
def get_lst_writable_linux_disks():
this_user = getpass.getuser()
lst_available_linux_disks = [str(Path.home())]
with open('/proc/mounts','r') as f:
data = f.readlines()
for line in data:
item = line.split(' ')
mount_point = item[1]
fs_type = item[2]
options = item[3]
if mount_point.startswith('/mnt') or (mount_point.startswith(f'/media/{this_user}') and fs_type != 'vfat' and 'rw' in options):
lst_available_linux_disks.append(mount_point)
return lst_available_linux_disks
print(get_lst_writable_linux_disks())
How would I do the same on Mac OS?
For a more bullet-proof method than parsing the human-readable output of
diskutil info -all, you could do something like this... (I don't quite like Apple's XML plist format; you'd think there was a better way to represent a dict than a flat key-value-key-value-... structure...)On my machine, this prints out
so besides "Writable" you will probably want to look at "Internal"...