Skip to content

Instantly share code, notes, and snippets.

View szhu's full-sized avatar

Sean Zhu szhu

  • Google
  • NYC / SF
  • 02:30 (UTC -04:00)
  • X @sfzhu
View GitHub Profile
@szhu
szhu / claude-code-sound-hooks-macos.json
Last active July 19, 2026 20:24
Claude Code hooks (macOS): play sounds on permission requests and when Claude + all subagents are done
{
"hooks": {
"PermissionRequest": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "afplay /System/Library/Sounds/Funk.aiff"
}
#!/bin/bash
#
# Run this now:
#
# bash -c "$(curl -fsSL "https://gist.githubusercontent.com/szhu/afd806ec1eb874848e1b4f412be7aaaf/raw/a6c51e413c65cf66019280c35e598ff6d5dd6cea/macos-install-legacy-hp-printer-drivers.sh")"
#
# This script makes it possible to install legacy HP printer drivers on modern
# versions of macOS.
#
# The HP 5.1.1 Printer Software Update (https://support.apple.com/en-us/106385)
// ==UserScript==
// @name Messenger Scraper
// @namespace https://github.com/szhu
// @version 0.20260429.5
// @match https://www.facebook.com/messages/*
// @match https://www.messenger.com/*
// @grant none
// @run-at document-idle
// ==/UserScript==
#!/usr/bin/env python3
import re
import subprocess
import sys
def run(args, echo=True):
if echo:
print(f"$ {' '.join(args)}")
r = subprocess.run(args, capture_output=True, text=True)
@szhu
szhu / textsub.js
Created January 27, 2026 18:20
Programmatically edit macOS text subsitutions
#!/usr/bin/env node
const { execSync } = require("child_process");
const path = require("path");
const plist = path.join(
process.env.HOME,
"Library/Preferences/.GlobalPreferences.plist",
);
const key = "NSUserDictionaryReplacementItems";
// ==UserScript==
// @name Prevent Input Zoom (robust)
// @match *://*/*
// @run-at document-start
// ==/UserScript==
const VIEWPORT_CONTENT =
"width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no";
function upsertViewportMeta() {

macOS Keyboard Remapper

A command-line tool to view, set, and clear custom keyboard mappings on macOS using hidutil.

Usage

# View current mapping
./macos_keys.py
#!/bin/bash
set -e
if [[ -z "$1" ]]; then
echo "Usage: $0 backup|backup-and-delete|restore"
exit 1
fi
CMD=$1
SELF=$0
@szhu
szhu / make-dynamic-wallpaper.sh
Created April 6, 2025 21:43
Make a basic macOS dynamic wallpaper
#!/bin/sh
# A script version of the instructions here: https://remove.codes/01-dynamic-wallpaper
set -e
# Helper functions.
verbose() {
echo >&2
echo $ "$@" >&2
#!/bin/bash
set -e
echo "==> Formulae" && brew leaves | xargs brew deps --tree --formula | sed '/^$/d' && echo && echo "==> Casks" && brew list --cask | xargs brew deps --tree --cask | sed '/^$/d'