Skip to content

Instantly share code, notes, and snippets.

View RhetTbull's full-sized avatar

Rhet Turnbull RhetTbull

View GitHub Profile
@RhetTbull
RhetTbull / RecentProjects.md
Created March 18, 2026 15:18
Automatically update macOS Finder Favorites sidebar to track recent project

Recent Projects in Finder Sidebar

Show your last 3 visited code projects as a Finder sidebar folder, updated automatically by zsh.

The Problem

There's no reliable public API for programmatically adding items to the macOS Finder sidebar Favorites. The old LSSharedFileList API was deprecated in macOS 10.11 and removed in 10.13. Tools like mysides no longer work on modern macOS (Sequoia).

I keep all my code projects in ~/code. I frequently want to drag files to a recently used project (I work mostly in the terminal). This shows a work-around to keep the Finder Favorites sidebar updated with the last 3 code projects I've worked on.

@RhetTbull
RhetTbull / pkginfo.py
Created October 14, 2025 14:55
Get the path to an installed python package and the version number.
#!/usr/bin/env python3
"""Get info about a Python package including install path and version"""
import argparse
import importlib.metadata as metadata
def main():
parser = argparse.ArgumentParser(description='Get info about a Python package')
parser.add_argument('package', help='Name of the Python package')
@RhetTbull
RhetTbull / creation_date.py
Created September 9, 2025 12:10
Set file creation date on macOS with python
#!/usr/bin/env python3
from datetime import datetime
from Foundation import NSURL, NSDate, NSURLCreationDateKey
def set_file_creation_date(file_path, creation_date):
"""
Sets the creation date of a file to the specified date
@RhetTbull
RhetTbull / venv.sh
Last active July 16, 2025 14:15
Automatically create Python venv with uv and configure direnv
#!/usr/bin/env bash
# venv.sh - Initialize a uv-based venv for a Python repo with direnv integration
set -e
# Remove .python-version if it exists
if [ -f ".python-version" ]; then
echo "🧹 Removing existing .python-version"
rm .python-version
@RhetTbull
RhetTbull / video_captions.py
Last active May 21, 2025 15:34
Generate video captions with Apple Intelligence
#!/usr/bin/env -S uv run --script
"""Generate captions for videos in Apple Photos using Apple's Media Analysis Service"""
# run with uv: `uv run https://gist.githubusercontent.com/RhetTbull/9035ff260d123413012758252a76d82a/raw/a5be13b0bcb1d5c2224ba1bb0828b652601b2482/video_captions.py`
# Following allows you to run the script with uv via `uv run video_captions.py`
# /// script
# dependencies = [
# "pyobjc-core",
# "pyobjc-framework-Photos",
@RhetTbull
RhetTbull / tzname.py
Last active February 3, 2025 11:13
Get the named timezone for a given location in python using native macOS CoreLocation APIs
"""Get named timezone for a location on macOS using CoreLocation
To use this script, you need to have pyobjc-core and pyobjc-framework-CoreLocation installed:
pip install pyobjc-core pyobjc-framework-CoreLocation
This script uses CoreLocation to get the timezone for a given latitude and longitude
as well as the timezone offset for a given date.
It effectively does the same thing as python packages like [tzfpy](https://pypi.org/project/tzfpy/)
@RhetTbull
RhetTbull / alias.py
Created November 17, 2024 01:30
Resolve macOS alias
"""Resolve path to macOS alias file; requires installation of pyobjc: `pip install pyobjc`"""
from Foundation import (
NSURL,
NSData,
NSError,
NSURLBookmarkResolutionWithoutMounting,
NSURLBookmarkResolutionWithoutUI,
)
@RhetTbull
RhetTbull / resolve_macos_alias.py
Last active February 24, 2026 06:47
Resolve macOS alias path in Python
"""Resolve path to macOS alias file
Given a path to a file that is a macOS alias, resolve the path to the original file
Requires: pip install pyobjc-core
"""
from Foundation import (
NSURL,
NSData,
@RhetTbull
RhetTbull / resolve_macos_alias_path.py
Created May 27, 2024 00:21
Resolve path to original file pointed to by macOS alias
"""Resolve path to original file pointed to by macOS alias
To use:
pip install pyobjc-core
python3 resolve_macos_alias_path.py /path/to/alias
"""
from Foundation import (
NSURL,
@RhetTbull
RhetTbull / get_latest_pypi_version.py
Created February 14, 2024 14:54
Get latest version of a python package from PyPI
"""Given a PyPI package name, print the latest version number of the package.
This uses the standard library instead of requests to avoid adding a dependency to the project.
"""
from __future__ import annotations
import json
import ssl
import sys