Skip to content

Instantly share code, notes, and snippets.

@gregneagle
Created February 23, 2023 23:13
Show Gist options
  • Save gregneagle/fd1373c016817b89224d4aab744c7918 to your computer and use it in GitHub Desktop.
Save gregneagle/fd1373c016817b89224d4aab744c7918 to your computer and use it in GitHub Desktop.
Using Apple's quarantine API from PyObjC
#!/usr/local/munki/munki-python
'''Demo only. Needs more robust error checking and handling'''
import os
from Foundation import NSURL, NSURLQuarantinePropertiesKey
def getQuarantineAttribute(pathname):
'''Returns a dict contaning quarantine info for pathname or None'''
url = NSURL.fileURLWithPath_isDirectory_(pathname, False)
(result, value, error) = url.getResourceValue_forKey_error_(None, NSURLQuarantinePropertiesKey, None)
return value
def removeQuarantineAttribute(pathname):
'''Removes quarantine info for pathname'''
url = NSURL.fileURLWithPath_isDirectory_(pathname, False)
(result, error) = url.setResourceValue_forKey_error_(None, NSURLQuarantinePropertiesKey, None)
for filename in os.listdir(os.path.expanduser("~/Downloads")):
if filename.endswith(".dmg"):
print(filename)
pathname = os.path.join(os.path.expanduser("~/Downloads"), filename)
print(getQuarantineAttribute(pathname))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment