The command getatime() in Python is different from the “Date Last Opened” in Finder (on macOS). How do I get the latter?

MacOS uses metadata that cannot be accessed by usual os* package. To do it directly you have to use coreservices api and read: kMDItemLastUsedDate From python that can be achieved by pyobjc.

You can also try to workaround it by executing mdls tool and parsing output:

mdls file.txt | grep -m 1 kMDItemLastUsedDate

and in python:

import subprocess
command = 'mdls file.txt | grep -m 1 kMDItemLastUsedDate'
output = subprocess.check_output(command, shell = True).decode('utf-8')
date_str = output.split('=')[1].strip() # in example '2020-09-23 08:43:17 +0000'

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top