Skip to content

Instantly share code, notes, and snippets.

@dsmortensen
Created May 12, 2023 13:29
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 dsmortensen/62e517c392a214c0f76b0bd1f0d9dc9d to your computer and use it in GitHub Desktop.
Save dsmortensen/62e517c392a214c0f76b0bd1f0d9dc9d to your computer and use it in GitHub Desktop.
This Jamf Pro extension attribute returns a list of the names and versions of all Safari add-ons installed for the current user. Inspired by the managed_python3 version of Chrome Extensions script by Elliot Jordan <elliot@lindegroup.com> Author: Daniel Mortensen <dmortensen@simonsfoundation.org>
#!/usr/local/bin/managed_python3
# Name: safari_extensions.py
# Description: This extension attribute returns a list of the names and
# versions of all Safari add-ons installed for the current
# user. Inspired by the managed_python3 version of Chrome Extensions script by Elliot Jordan <elliot@lindegroup.com>
# Author: Daniel Mortensen <dmortensen@simonsfoundation.org>
# Created: 2022-10-28
# Last Modified: 2022-10-28
# Version: 1.0
import os
import xml.etree.ElementTree as ET
import re
import sys
from SystemConfiguration import SCDynamicStoreCopyConsoleUser
def get_current_user():
username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]
return username
def get_extensions(username):
extensions_list = ("/Users/%s/Library/Containers/com.apple.Safari/"
"Data/Library/Safari/AppExtensions/Extensions.plist" % username)
return extensions_list
def print_results(extensions_list):
tree = ET.parse(extensions_list)
root = tree.getroot()
list = ""
for key in root.iter('key'):
match = re.search('com.',key.text)
if match:
result = key.text
list = list + result + "\n"
return list.strip()
def main():
username = get_current_user()
extensions_list = get_extensions(username)
#results = parse_results(manifest_list)
to_echo = print_results(extensions_list)
print("<result>%s</result>" % to_echo)
if __name__ == '__main__':
main()
@Oh4sh0
Copy link

Oh4sh0 commented Apr 18, 2024

I couldn't get this to work on macOS 14.5b2.

mzd175@f02f4b0d458f com.apple.Safari % python3 /Users/myuser/Desktop/testsafari.py
Traceback (most recent call last):
File "/Users/mzd175/Desktop/testsafari.py", line 17, in
from SystemConfiguration import SCDynamicStoreCopyConsoleUser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment