Skip to content

Instantly share code, notes, and snippets.

View jorgensandhaug's full-sized avatar

Jørgen Sandhaug jorgensandhaug

View GitHub Profile
@jorgensandhaug
jorgensandhaug / install_compress_quickaction.XXXXXX.XDlThKvl0e
Created November 1, 2025 09:23
Installer for macOS Quick Action: Compress images (10 MB)
#!/bin/bash
set -euo pipefail
WF_TITLE="Compress images (10 MB)"
WF_DIR="$HOME/Library/Services/${WF_TITLE}.workflow"
WF_CONTENTS="$WF_DIR/Contents"
SCRIPT="$HOME/.local/bin/compress_to_10mb.py"
RAW_URL="https://gist.githubusercontent.com/jorgensandhaug/05c3066a4878497cc3718cd3233af02c/raw/compress_to_10mb.py"
echo "Installing Quick Action: ${WF_TITLE}"
@jorgensandhaug
jorgensandhaug / install_compress_quickaction.XXXXXX.dXwEcZK73G
Created November 1, 2025 09:22
Installer for macOS Quick Action: Compress images (10 MB)
#!/bin/bash
set -euo pipefail
WF_TITLE="Compress images (10 MB)"
WF_DIR="$HOME/Library/Services/${WF_TITLE}.workflow"
WF_CONTENTS="$WF_DIR/Contents"
SCRIPT="$HOME/.local/bin/compress_to_10mb.py"
RAW_URL="https://gist.githubusercontent.com/jorgensandhaug/05c3066a4878497cc3718cd3233af02c/raw/compress_to_10mb.py"
echo "Installing Quick Action: ${WF_TITLE}"
@jorgensandhaug
jorgensandhaug / install_compress_quickaction.XXXXXX.3XfTJVJ2qC
Created November 1, 2025 09:14
Installer for macOS Quick Action: Compress images (10 MB)
#!/bin/bash
set -e -o pipefail
WF_TITLE="Compress images (10 MB)"
WF_DIR="/Users/jorgensandhaug/Library/Services/.workflow"
WF_CONTENTS="/Contents"
SCRIPT="/Users/jorgensandhaug/.local/bin/compress_to_10mb.py"
RAW_URL="https://gist.github.com/jorgensandhaug/05c3066a4878497cc3718cd3233af02c/raw/compress_to_10mb.py"
echo "Installing Quick Action: "
@jorgensandhaug
jorgensandhaug / compress_to_10mb.py
Created November 1, 2025 08:47
Compress images ≤10 MB Quick Action script
#!/usr/bin/env python3
import argparse, os, shutil, subprocess, sys, tempfile, time, unicodedata
from pathlib import Path
TARGET_BYTES = 10 * 1024 * 1024
RUN_TS = time.strftime("%Y%m%d-%H%M%S")
os.environ["PATH"] = os.environ.get("PATH", "") + ":/opt/homebrew/bin:/usr/local/bin"
MOZ = Path("/opt/homebrew/opt/mozjpeg/bin")
CJPEG = str(MOZ / "cjpeg") if (MOZ / "cjpeg").exists() else "cjpeg"
DJPEG = str(MOZ / "djpeg") if (MOZ / "djpeg").exists() else "djpeg"
JPEGTRAN = str(MOZ / "jpegtran") if (MOZ / "jpegtran").exists() else "jpegtran"