Created
August 25, 2022 08:41
-
-
Save sunsong/a8f91cbed7b628decba6c62baef70c4f to your computer and use it in GitHub Desktop.
Get Installed Applications in MacOS
This file contains hidden or 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/python3 | |
| # https://stackoverflow.com/questions/50708348/using-python-to-find-mac-uuid-serial-number | |
| import os | |
| import subprocess | |
| irrelevant_files = [ | |
| ".localized", | |
| ] | |
| def get_serial_number(): | |
| cmd = "system_profiler SPHardwareDataType | awk '/Serial Number/ {print $4}'" | |
| result = subprocess.run(cmd, stdout=subprocess.PIPE, shell=True, check=True) | |
| serial_number = result.stdout.strip().decode() | |
| return serial_number | |
| def get_installed_applications(): | |
| listed_items = os.listdir("/Applications") | |
| apps = [] | |
| for item in listed_items: | |
| if item not in irrelevant_files: | |
| apps.append(item) | |
| return [app.split(".app")[0] for app in apps] | |
| def main(): | |
| serial_number = get_serial_number() | |
| installed_apps = ", ".join(get_installed_applications()) | |
| print("Your Mac Serial Number: %s" % serial_number) | |
| print("The apps you installed: %s" % installed_apps) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment