Skip to content

Instantly share code, notes, and snippets.

View RhetTbull's full-sized avatar

Rhet Turnbull RhetTbull

View GitHub Profile
@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 June 1, 2025 14:36
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
@RhetTbull
RhetTbull / pyapp.sh
Last active February 11, 2024 00:40
Run PyApp to build a python app
#!/bin/bash
# PyApp Runner
# This script is used to build and copy the PyApp executable
# See https://ofek.dev/pyapp/latest/how-to/ for more information on PyApp.
# Change this to the path where pyapp is installed
PYAPP="/path/to/pyapp-latest"
# Check that both arguments are provided
@RhetTbull
RhetTbull / pyapp_runner.sh
Last active February 11, 2024 22:06
Run PyApp on a remote server (tested only on macOS)
#!/bin/bash
# PyApp Runner
# This script is used to build and copy the PyApp executable from a remote server.
# See https://ofek.dev/pyapp/latest/how-to/ for more information on PyApp.
# The remote server must have PYAPP defined in the ~/.zshenv file
# to point to the install location of pyapp.
# For example:
# echo 'export PYAPP="/Users/johndoe/code/pyapp-latest"' >> ~/.zshenv
# For code signing to work via ssh, you must first run this one time on the machine via GUI
@RhetTbull
RhetTbull / minimal.py
Last active December 9, 2024 16:08
Implements a minimalist macOS Cocoa application in python using pyobjc that doesn't require a NIB file
"""Implements a minimalist Cocoa application using pyobjc
Based on the example found here:
https://www.cocoawithlove.com/2010/09/minimalist-cocoa-programming.html
To run this:
- save as minimal.py
- pip3 install pyobjc
- python3 minimal.py
@RhetTbull
RhetTbull / image_metadata.py
Last active October 23, 2023 19:03
Get EXIF/IPTC/XMP metadata from an image file on macOS in python using CoreGraphics via pyobjc
"""Get EXIF/IPTC/XMP metadata from an image file on macOS using CoreGraphics via pyobjc.
Requires installation of the following [pyobjc](https://pyobjc.readthedocs.io/en/latest/index.html) packages:
`pip install pyobjc-core pyobjc-framework-Quartz`
This module provides 3 public functions:
- get_image_properties(): Returns the metadata properties dictionary from the image at the given path.
- get_image_xmp_metadata(): Returns the XMP metadata dictionary from the image at the given path.