Created
February 23, 2023 23:13
-
-
Save gregneagle/fd1373c016817b89224d4aab744c7918 to your computer and use it in GitHub Desktop.
Using Apple's quarantine API from PyObjC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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