This script extracts icons from MacOS applications and system resources, then converts them to a specific JSON format with Base64-encoded images.
# Just run a script with default settings
uv run flexbar_macos_icon_extractor.py| #!/usr/bin/env uv run --script | |
| # /// script | |
| # dependencies = [ | |
| # "selectolax", | |
| # "pathvalidate", | |
| # ] | |
| # /// | |
| import datetime | |
| import json | |
| import logging |
| // This script shows a random Scriptable API in a widget. The script is meant to be used with a widget configured on the Home Screen. | |
| // You can run the script in the app to preview the widget or you can go to the Home Screen, add a new Scriptable widget and configure the widget to run this script. | |
| // You can also try creating a shortcut that runs this script. Running the shortcut will show widget. | |
| let api = await randomAPI() | |
| let widget = await createWidget(api) | |
| if (config.runsInWidget) { | |
| // The script runs inside a widget, so we pass our instance of ListWidget to be shown inside the widget on the Home Screen. | |
| Script.setWidget(widget) | |
| } else { | |
| // The script runs inside the app, so we preview the widget. |
| // Variables used by Scriptable. | |
| // These must be at the very top of the file. Do not edit. | |
| // icon-color: blue; icon-glyph: users; | |
| // Config | |
| // You can change the config here | |
| const WIDGET_TITLE = 'Persons at home'; | |
| // ========================================= | |
| // PLEASE, DON'T CHANGE ANYTHING BELOW THIS COMMENT, | |
| // IF YOU DON'T KNOW WHAT YOU ARE DOING | |
| // ========================================= |
| 'use strict' |
| # Var 9 | |
| # %% | |
| # ============================================================================= | |
| from logging import debug, basicConfig, DEBUG | |
| # basicConfig(level=DEBUG) | |
| ID_KEY = "id" | |
| # %% | |
| # ============================================================================= |
| import sys | |
| from platform import system | |
| from typing import Tuple | |
| class Color: | |
| COLOR_SYMBOL = "\x1b" | |
| # ATTRIBUTES | |
| NORMAL = 0 |
| from io import TextIOWrapper | |
| from sys import stdout | |
| from typing import List | |
| def print_matrix(matrix: List[List[int]], file: TextIOWrapper = stdout) -> None: | |
| width, height = len(matrix), len(matrix[0]) | |
| # max length for beautify | |
| l: int = len(str(1 + max( | |
| width, |
| def split_string(string): | |
| buf = [] | |
| result = [] | |
| buffer = "" | |
| for i in string: | |
| if i in "()[]{}\"'": | |
| continue | |
| if i in ".?!\n": | |
| result.append(buf + [buffer]) | |
| buffer = "" |