Search code examples
pythonplistmacos-sequoia

python - macOS Sequoia: reading plist


trying to read plist in macOS sequoia. I did find https://pypi.org/project/plists/#description but it doesn't install

How can I use python plists package?

pip3 install plists

Gives the following error:

Defaulting to user installation because normal site-packages is not writeable
Collecting plists
  Using cached plists-0.0.4.tar.gz (7.4 kB)
    ERROR: Command errored out with exit status 1:
     command: /Library/Developer/CommandLineTools/usr/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_4670f12a38cc4539a382c3ec2a0ed312/setup.py'"'"'; __file__='"'"'/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_4670f12a38cc4539a382c3ec2a0ed312/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-pip-egg-info-iufqpu7j
         cwd: /private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_4670f12a38cc4539a382c3ec2a0ed312/
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_4670f12a38cc4539a382c3ec2a0ed312/setup.py", line 80
        print "PDIR: ", pdir(), os.listdir(pdir())
              ^
    SyntaxError: invalid syntax
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/71/1b/24d3f3885744b41e4d58774bce89b3a20966960cd41c9d3d787485e01e1d/plists-0.0.4.tar.gz#sha256=d48b2390c27d957cf54791001f679f1c96d2652b599a85a3d9d2cc4567c02ce0 (from https://pypi.org/simple/plists/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Using cached plists-0.0.3.tar.gz (6.9 kB)
    ERROR: Command errored out with exit status 1:
     command: /Library/Developer/CommandLineTools/usr/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_b5366a04f87f4cc0be570288a1a967b6/setup.py'"'"'; __file__='"'"'/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_b5366a04f87f4cc0be570288a1a967b6/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-pip-egg-info-qqjk06qw
         cwd: /private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_b5366a04f87f4cc0be570288a1a967b6/
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_b5366a04f87f4cc0be570288a1a967b6/setup.py", line 80
        print "PDIR: ", pdir(), os.listdir(pdir())
              ^
    SyntaxError: invalid syntax
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/f6/bf/d7e74c38a6d8d4993ac2631fc327c3439e06e7d01ebf54f86202393e548f/plists-0.0.3.tar.gz#sha256=c3ac16d5b6262552ac5da8ac410fa7a85e918e11ff708cf5b4958f240619029b (from https://pypi.org/simple/plists/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Using cached plists-0.0.2.tar.gz (6.9 kB)
    ERROR: Command errored out with exit status 1:
     command: /Library/Developer/CommandLineTools/usr/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_accf278426034dce9e1b20c280eb6e51/setup.py'"'"'; __file__='"'"'/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_accf278426034dce9e1b20c280eb6e51/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-pip-egg-info-y01b3lan
         cwd: /private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_accf278426034dce9e1b20c280eb6e51/
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_accf278426034dce9e1b20c280eb6e51/setup.py", line 80
        print "PDIR: ", pdir(), os.listdir(pdir())
              ^
    SyntaxError: invalid syntax
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/1f/38/e451a4895d12d241f2bca8061a2d5c4d376e2e90739d892977a1266e227f/plists-0.0.2.tar.gz#sha256=ed39b1dad1b0de1dfc4853e70c39bd7a14e5e3b7b86ad76c22754d49833976fd (from https://pypi.org/simple/plists/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
  Using cached plists-0.0.1.tar.gz (6.2 kB)
    ERROR: Command errored out with exit status 1:
     command: /Library/Developer/CommandLineTools/usr/bin/python3 -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_6072274ea7ea4f6bafbe428f95e5feb1/setup.py'"'"'; __file__='"'"'/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_6072274ea7ea4f6bafbe428f95e5feb1/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-pip-egg-info-8esq59jv
         cwd: /private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_6072274ea7ea4f6bafbe428f95e5feb1/
    Complete output (6 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/private/var/folders/9j/s_r_lpgs2tj1v838wj4h716c0000gn/T/pip-install-eh0uq6op/plists_6072274ea7ea4f6bafbe428f95e5feb1/setup.py", line 80
        print "PDIR: ", pdir(), os.listdir(pdir())
              ^
    SyntaxError: invalid syntax
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/2b/67/18ade2a5d79733595d53a0ae174bdf11d28ac2f649db68b2377148291ad8/plists-0.0.1.tar.gz#sha256=3c452ad85861ada94f3199658c0fadd860a3c74388346e9c58ff74132807e893 (from https://pypi.org/simple/plists/). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement plists (from versions: 0.0.3.macosx-10.10-x86_64, 0.0.4.macosx-10.10-x86_64, 0.0.1, 0.0.2, 0.0.3, 0.0.4)
ERROR: No matching distribution found for plists
WARNING: You are using pip version 21.2.4; however, version 24.3.1 is available.
You should consider upgrading via the '/Library/Developer/CommandLineTools/usr/bin/python3 -m pip install --upgrade pip' command.

Solution

  • Looks like this package is already merged into python3 - https://docs.python.org/3/library/plistlib.html

    import plistlib
    file_name = "/Library/Preferences/com.apple.TimeMachine.plist"
    with open(file_name, 'rb') as infile:
        plist = plistlib.load(infile)
    print(plist["LastConfigurationTraceDate"])