Skip to content

Instantly share code, notes, and snippets.

@oaustegard
Created October 18, 2023 16:16
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 oaustegard/dd5ff80d680f1a692b667cb4bbe213fc to your computer and use it in GitHub Desktop.
Save oaustegard/dd5ff80d680f1a692b667cb4bbe213fc to your computer and use it in GitHub Desktop.
Get the software installed on a mac
import os
import csv
import subprocess
def run_command(command):
result = subprocess.run(command, capture_output=True, text=True, shell=True)
return result.stdout.strip().split('\n')
def get_apps_from_directory(directory_path):
if not os.path.exists(directory_path):
return []
return [app.replace('.app', '') for app in os.listdir(directory_path) if app.endswith('.app')]
def get_installed_brew_packages():
return run_command("brew list --formula")
def get_installed_ports():
return run_command("port installed | awk '{print $1}'")
def get_native_software():
system_apps = get_apps_from_directory("/Applications")
user_apps = get_apps_from_directory("/System/Applications")
user_local_apps = get_apps_from_directory(os.path.expanduser("~/Applications"))
brew_packages = get_installed_brew_packages()
ports_packages = get_installed_ports()
all_software = system_apps + user_apps + user_local_apps + brew_packages + ports_packages
return sorted(list(set(all_software)))
def get_computer_name():
result = subprocess.run(["scutil", "--get", "ComputerName"], capture_output=True, text=True)
return result.stdout.strip()
if __name__ == "__main__":
# Set the output file name as the current user's username_computername_mac_sw_inventory.csv
output_file_name = f"{os.environ['USER']}_{get_computer_name()}_mac_sw_inventory.csv"
native_software = get_native_software()
with open(output_file_name, 'w', newline='') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(["Native Software"])
for software in native_software:
writer.writerow([software])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment