Sadly Apple continue to make life harder for us Mac admins. 😢
I currently need to uninstall Sophos Anti-Virus from every Mac so I can then replace it with an alternative. (This is because Sophos still have not released a fully native Apple Silicon version.)
It would be easy to use a script to run the Sophos uninstall command, bypassing the anti Tamper measures of Sophos is also easy. The problem is an Apple one.
Sophos correctly uses System Extensions. For macOS Big Sur there seems to be only two working approaches that let you uninstall System Extensions. Either you can turn off SIP and do whatever you want, or the only other method - and clearly the one Apple want you to use is to drag the application that contains the System Extensions to the Bin. This then triggers an OS dialog asking for user approval to remove the contained system extensions. If you otherwise uninstall Sophos, or drag the wrong thing, or use a script to delete items, the System Extensions do not get uninstalled and will remain forever more.
As mentioned this is not Sophos' fault and affects any other software using System Extensions. As one example article on this topic see - https://grahamrpugh.com/2021/04/06/delete-system-extension-command-line.html
In theory the systemextensionsctl tool has an uninstall option and this indeed did work in Catalina but it does not if SIP is enabled on macOS Big Sur.
So, what I am trying to do is write a shell script that uses osascript to 'tell' the Finder to move the required applications to the Bin. In fact before I get that far I wisely decided to do a much simpler and safer test which was to have a shell script which uses osascript and tells the Finder to open a new Finder window.
#!/bin/sh
osascript <<EOF
tell application "Finder"
activate
make new Finder window
end tell
EOF
This script itself seems fine but I am hitting a problem with it resulting in
Running script Test osascript...
Script exit code: 1
Script result: 37:59: execution error: Not authorised to send Apple events to Finder. (-1743)
I have created a PPPC profile in Jamf Pro to allow Jamf itself as per https://github.com/jamf/JamfPrivacyPreferencePolicyControlProfiles and /usr/bin/osascript and Terminal.app permissions to send Apple Events to the Finder. Attached is an example of this PPPC.
So why is this still failing?
Note: The intent is that the final script tells the Finder to move the offending files to the Bin, which will trigger the Apple dialogs asking the user to approve this, this uninstalls the System Extensions, and I will then in the same script complete the rest of uninstalling Sophos and then trigger a reboot. After the reboot the replacement Anti-Virus tool will be installed.