Created
October 18, 2023 16:16
-
-
Save oaustegard/dd5ff80d680f1a692b667cb4bbe213fc to your computer and use it in GitHub Desktop.
Get the software installed on a mac
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
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