EA for Internal Disk Format

primalcurve
New Contributor III
#!/System/Library/Frameworks/Python.framework/Versions/Current/bin/python
# -*- coding: utf-8 -*-

import subprocess
import plistlib
import sys


sysp_out = subprocess.check_output(["system_profiler", "SPStorageDataType", "-xml"])
sysp_items = plistlib.readPlistFromString(sysp_out)[0]["_items"]

internal_disks = []

for item in sysp_items:
    if item["physical_drive"]["is_internal_disk"] == "yes":
        internal_disks.append(item["bsd_name"] + ":" + item["file_system"])

if internal_disks:
    sys.stdout.write("<result>" + "
".join(internal_disks) + "</result>")
else:
    sys.stdout.write("<result>Unknown</result>")

As bash one-liner (with no output on error)

python -c 'import subprocess; import sys; import plistlib; sys.stdout.write("<result>" + [i if i["physical_drive"]["is_internal_disk"] == "yes" else for i in plistlib.readPlistFromString(subprocess.check_output(["system_profiler", "SPStorageDataType", "-xml"]))[0]["_items"]][0]["file_system"] + "</result>")'
0 REPLIES 0