Last active
April 16, 2018 11:46
-
-
Save erikng/add9fabe43a9afc46b959f2844940271 to your computer and use it in GitHub Desktop.
32bitapps.py
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/bin/python | |
import subprocess | |
import plistlib | |
cmd = ['/usr/sbin/system_profiler', '-xml', 'SPApplicationsDataType'] | |
proc = subprocess.Popen(cmd, shell=False, bufsize=-1, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
output, err = proc.communicate() | |
plist = plistlib.readPlistFromString(output) | |
items = plist[0]['_items'] | |
for item in sorted(items, key=lambda x: x.get('path')): | |
if 'no' in item.get('has64BitIntelCode'): | |
print [item.get('path'), item.get('_name'), item.get('version')] |
This works a lot faster -
mdfind '( kMDItemKind=="Application" && kMDItemExecutableArchitectures != "x86_64" )'
But results aren't exactly the same - still trying to figure out why
This is better
mdfind '( kMDItemKind=="Application" && kMDItemExecutableArchitectures != "x86_64" && kMDItemExecutableArchitectures == "i386" )'
Now my results match yours.
And if you want to output the results, you could do something like
#!/bin/bash
# Setting IFS Env to only use new lines as field seperator
IFS=$'\n'
for app in $(mdfind '( kMDItemKind=="Application" && kMDItemExecutableArchitectures != "x86_64" && kMDItemExecutableArchitectures == "i386" )')
do
arch=$(mdls -name kMDItemExecutableArchitectures $app | awk 'NR>1{print $1}' RS=\( FS=\) | tr -d "[:space:]")
printf "\n$arch%15s\t$app"
done
I took @igeekjsc's idea and created a Jamf Extension Attribute. Now each computer record will show all installed 32-bit apps.
Side Note: The reason I save to file and then read back in is so that the contents of the <result></result>
tags is formatted nicely within Jamf.
#!/bin/bash
# 32-Bit_App_Audit.sh (Jamf Extension Attribute)
# Written by Caine Hörr
# Written on 2018-02-08
# Code heavily "borrowed" from https://gist.github.com/erikng/add9fabe43a9afc46b959f2844940271
# As written by https://gist.github.com/igeekjsc
# Declare the path and filename to be used...
AuditFile=/private/tmp/32-Bit_App_Audit.txt
# Setting IFS Env to only use new lines as field seperator
IFS=$'\n'
# Put everything into a variable for safe keeping...
AppAudit=$(for app in $(mdfind '( kMDItemKind=="Application" && kMDItemExecutableArchitectures != "x86_64" && kMDItemExecutableArchitectures == "i386" )')
do
arch=$(mdls -name kMDItemExecutableArchitectures $app | awk 'NR>1{print $1}' RS=\( FS=\) | tr -d "[:space:]")
VersionCheck=`plutil -p $app/Contents/Info.plist | grep "CFBundleShortVersionString" | awk '{gsub(/"/, ""); print $3}'`
# printf "\n$arch%15s\t$app%15s\t$VersionCheck"
printf "\n* $app, $VersionCheck"
done)
# Put contents of the variable into the afforementioned file for even safer keeping...
echo "$AppAudit" > "$AuditFile"
# Read in the file and format for Jamf as an Extension Attribute...
echo "<result>$(cat "$AuditFile")</result>"
exit
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably overkill, but I added Unicode handling and CSV output: https://gist.github.com/MagerValp/f926e84ac2e43d1f698343f1d6848de0