Skip to content

Instantly share code, notes, and snippets.

@erikng
Last active April 16, 2018 11:46
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erikng/add9fabe43a9afc46b959f2844940271 to your computer and use it in GitHub Desktop.
Save erikng/add9fabe43a9afc46b959f2844940271 to your computer and use it in GitHub Desktop.
32bitapps.py
#!/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')]
@MagerValp
Copy link

Probably overkill, but I added Unicode handling and CSV output: https://gist.github.com/MagerValp/f926e84ac2e43d1f698343f1d6848de0

@str8outtajc
Copy link

This works a lot faster -

mdfind '( kMDItemKind=="Application" && kMDItemExecutableArchitectures != "x86_64" )'

But results aren't exactly the same - still trying to figure out why

@str8outtajc
Copy link

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

@cainehorr
Copy link

cainehorr commented Feb 9, 2018

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