Skip to content

Instantly share code, notes, and snippets.

@natewalck
Forked from gregneagle/quarantine_demo.py
Created February 24, 2023 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save natewalck/37f8a2c2d56328f8b7ee4737bb8d3888 to your computer and use it in GitHub Desktop.
Save natewalck/37f8a2c2d56328f8b7ee4737bb8d3888 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