-
Notifications
You must be signed in to change notification settings - Fork 26
macOS Usage
Joshua H. Fogg edited this page Apr 14, 2021
·
1 revision
While the main project only supports Linux, @BKrajancic has contributed this script which allows for exporting the base SVG icons into a .icn
format which can be used to replace folder or application icons on macOS. It requires Cairo to be installed for Python 3 and libicns to be installed system wide for the png2icns
command.
"""Make icns that can be used on macOS."""
import os
import pathlib
import cairosvg
from subprocess import PIPE, call
def _make_icns():
for root, _, files in os.walk("./styles", topdown=False):
for name in files:
if name.endswith(".svg"):
source = os.path.sep.join(pathlib.Path(root).parts)
out_path = pathlib.Path("icns") / source
if ("64" not in out_path.parts and
"scalable" not in out_path.parts):
continue
png_path_128 = os.path.sep.join(out_path.parts)
png_path_128 = png_path_128.replace("64", "128")
os.makedirs(str(png_path_128), exist_ok=True)
png_name = name.replace(".svg", ".png")
png_path_128 = os.path.join(png_path_128, png_name)
cairosvg.svg2png(
url=str(pathlib.Path(source) / name),
write_to=png_path_128,
output_width=128,
output_height=128
)
icn_path = png_path_128.replace(".png", ".ico")
call(["png2icns", icn_path, png_path_128],
stdout=PIPE, stderr=PIPE)
os.remove(png_path_128)
if __name__ == "__main__":
_make_icns()