Skip to content

Instantly share code, notes, and snippets.

@oPromessa
oPromessa / persons.py
Created December 15, 2025 18:52
osxphotos export: add to exported images keyword "person:PersonName_A" based on Photos Faces/People information
""" Custom python function as an osxphotos template filter
Use as an option to osxphotos export template in format:
"{template_field|sort|persons.py::myfilter}"
For example:
osxphotos export /path/to/export --export-by-date --exiftool --exiftool-merge-keywords --keyword-template "{keyword}" --keyword-template "{person|sort|function:persons.py::myfilter}"
The filter function will receive a list of strings even if the template renders to a single value.
You should expect a list and return a list and be able to handle multi-value templates like {keyword}
"""Move all albums that have the same name as their parent folder and are
alone in that folder one folder up.
"""
from __future__ import annotations
import logging
import re
import sys
@oPromessa
oPromessa / .zlogin
Created September 20, 2025 19:03
macOS: Terminal: zsh function to show status of Time Machine: attempts to mount SMB Backup destinations and list the backups.
#------------------------------------------------------------------------------
# Report Time Machine status
function tminfo {
function mount_table() {
mount | awk '
{
# Find "on" and "(" positions
for(i=1;i<=NF;i++) {
if($i=="on") on_idx=i
@oPromessa
oPromessa / check_timezone.v2.py
Created May 15, 2025 19:21
Mac Photos: identify all pics with mismatched Timezone vs GPS Location and prepare commands to fix it: osxphotos timewarp and osxphotos push-exif. See https://github.com/RhetTbull/osxphotos/issues/1788
#!/usr/bin/env python3
"""This script checks and fixes timezone inconsistencies in photos
managed by the Photos app on macOS.
It uses the `osxphotos` library to access photo metadata and the
`timezonefinder` library to determine timezones based on GPS coordinates.
Use with Python 3.11 or later.
Required Python libraries: `pip install osxphotos pytz timezonefinder rich`
@oPromessa
oPromessa / ncheck_dst.py
Last active August 28, 2024 15:21
Compute UTC offset respecting DST for a GPS Location (latitude, Longitude) and a given date/time
"""
by oPromessa, 2024
Published on https://gist.github.com/oPromessa/85c2040a0187fe6868ead8a4b0ed912e
Based on Location (latitude, longitude) and date time (YYYY:MM:DD HH:MM:SS)
finds the corresponding Timezone and assocaited DST True/False and
returns UTS Offset in the format [+-]HH:MM
Usage: ncheck_dst.py [OPTIONS] LATITUDE LONGITUDE DATE_STR
@oPromessa
oPromessa / .bash-login.md
Last active January 16, 2023 23:17
exiftool related functions simplify repetitive tasks.

Place this on your ~/.bash_login file so that functions are available on your BASH upon every login.

###############################################################################
#
# Standard Alias: Uncomment the ALIASES entries you elect to use from this section
#
###############################################################################
#alias vibashl='vi ~/.bash_login'

#alias ll='ls -lisahG'
@oPromessa
oPromessa / .exiftool_bash_aliases
Last active October 20, 2018 15:33
Helpful bash exiftool related functions to set various EXIF and date/time values on pics and movies files.
###############################################################################
#
# EXIFTOOL related commands
#
###############################################################################
if [ ! -f ~/EXIF_format.fmt ]
then
cat > ~/EXIF_format.fmt << EOF
#[HEAD]Directory|FileName|Make|DateTimeOriginal|FileModifyDate|CreateDate|Keywords|Subject|ImageOrientation|Caption-Abstract|ModifyDate|Description
\$Directory|\$FileName|\$Make|\$DateTimeOriginal|\$FileModifyDate|\$CreateDate|\$Keywords|\$Subject|\$ImageOrientation|\$Caption-Abstract|\$ModifyDate|\$Description
#!/usr/bin/env python
"""
by oPromessa, 2018
flickrapi login example (python 2.7 and 3.6 compatible)
"""
import sys
import os
import logging
import flickrapi