Extract all app logos to PNG

15 Aug 2022

Getting apps logos from local .app folders

from slugify import slugify

import glob
import os
import shutil

list_locations = [
    '/Applications/*.app',
    '/Applications/Setapp/*.app',
    '/Volumes/Macintosh HD-1/Applications/*.app',
]

list_errors = []

count_file = 0

for location in list_locations:

    parts = location.split('*')
    prefix = len(parts[0])

    list_of_files = glob.glob(location)

    print()
    for file in list_of_files:
        count += 1
        # print(file)

        app = file[prefix:-4]
        print(app)
        slug = slugify(app)

        for root, dirs, files in os.walk(file):
            for name in files:
                if name.endswith((".icns")):
                    count_file += 1

                    print(f"{root}/{name}")

                    try:
                        shutil.copy2(f'{root}/{name}', f"/path/to/output/folder/{slug}_{name}.icns")
                    except:
                        list_errors.append(name)
                        continue

Batch converting all to PNG

# Convert .icns files to .png 

import icnsutil

for root, dirs, files in os.walk("/path/to/folder/with/icns/files"):
    for name in files:
        if name.endswith((".icns")):
            count += 1
            file_path = f"{root}/{name}"
            print(file_path)
            slug = name[:-5]
            print(slug)

            img = icnsutil.IcnsFile(file_path)
            output_path = f"/path/to/output/folder/{slug}"
            os.makedirs(output_path)
            img.export(output_path, allowed_ext='png', convert_png=True)

links

social