Macos12.3 - NoMad python 2 deprecation and unable to use launchtl

New Contributor III



Can someone look at the script below and help provide an update so we can get this to work with 12.3 OS? python3 command asks for xcode install which we don't want to perform on here. Would be super helpful. We use it to push installs and updates of the app as well. we have our own icon dropper as pkg file as well



log() {
echo "$1"
/usr/bin/logger -t "NoMAD Installer:" "$1"
log "Installing"

tempDir=$(/usr/bin/mktemp -d -t "NoMAD_Installer")

cleanUp() {
log "Performing cleanup tasks..."
/bin/rm -r "$tempDir"

trap cleanUp exit

loggedInUserPid=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; username = SCDynamicStoreCopyConsoleUser(None, None, None)[1]; print(username);')

launchctlCmd=$(python -c 'import platform; from distutils.version import StrictVersion as SV; print("asuser") if SV(platform.mac_ver()[0]) >= SV("10.10") else "bsexec"')


log "Downloading NoMAD.pkg..."
/usr/bin/curl -s $packageDownloadUrl -o "$tempDir/NoMAD.pkg"
if [ $? -ne 0 ]; then
log "curl error: The package did not successfully download"; exit 1

pkgSignatureCheck=$(/usr/sbin/pkgutil --check-signature "$tempDir/NoMAD.pkg")
if [ $? -ne 0 ]; then
log "pkgutil error: The downloaded package did not pass the signature check"; exit 1

log "Installing"
/usr/sbin/installer -pkg "$tempDir/NoMAD.pkg" -target /
if [ $? -ne 0 ]; then
log "installer error: The package did not successfully install"; exit 1

log "Writing LaunchAgent..."
read -d '' launchAgent <<"EOF"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
echo "$launchAgent" > /Library/LaunchAgents/com.trusourcelabs.NoMAD.plist

/usr/sbin/chown root:wheel /Library/LaunchAgents/com.trusourcelabs.NoMAD.plist
/bin/chmod 644 /Library/LaunchAgents/com.trusourcelabs.NoMAD.plist

log "Loading LaunchAgent..."
/bin/launchctl "$launchctlCmd" "$loggedInUserPid" /bin/launchctl load /Library/LaunchAgents/com.trusourcelabs.NoMAD.plist
if [ $? -ne 0 ]; then
log "launchctl error: The LaunchAgent failed to load"; exit 1

log " install complete"
exit 0




Legendary Contributor III

Honored Contributor III

@tegus232 Neither of those calls to python is necessary. You can replace the line that get the loggedInUserPid with:


currentUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ { print $3 }' )
loggedInUserPid=$(id -u "$currentUser")


And unless you need to support versions of macOS back to 10.10, which Jamf Pro  doesn't even support these days, replace the call to set launchctlCmd with:




 (There's actually other more cleanup that could be done, but those 2 changes will eliminate the python usage in your script)