This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Update favorites in Photos based on values in a JSON file produced by this iOS Shortcut: https://www.icloud.com/shortcuts/2057bcae53b146b3847260dc0cced1b6 | |
First install osxphotos: https://github.com/RhetTbull/osxphotos | |
Run with `osxphotos run update_favorites.py --help` to see help | |
The input JSON file has form: | |
{"28":{"date":"2021-08-05 13:18:37.232-0700","name":"IMG_5702"}} | |
Where "28" is the index (not used), date is photo creation date and name is stem of photo name. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Programatically set the Mac Desktop wallpaper from python | |
Also shows how to load a framework with pyobjc | |
Source: https://github.com/jbmorley/download-bing-image | |
""" | |
import objc | |
from CoreFoundation import CFUUIDCreateFromString | |
from Foundation import NSBundle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Get offset seconds from UTC from a datetime""" | |
import datetime | |
time1 = datetime.datetime(2021, 9, 1, 0, 0, 0, 0, tzinfo=datetime.timezone.utc) | |
offset_seconds = time1.tzinfo.utcoffset(time1).total_seconds() | |
print(time1, offset_seconds) | |
time2 = datetime.datetime( | |
2021, 9, 1, 0, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(seconds=-25200)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Refuse to commit files with the string ZZZ present | |
# I frequently use ZZZ to mark a spot where I'm working on an issue so I can come back to it | |
# | |
NOCOMMIT="ZZZ" | |
files=$(git diff-index --name-status --cached HEAD | grep -v ^D | cut -c3-) | |
if [ "$files" != "" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# From https://stackoverflow.com/a/68876046/1319998, which is itself inspired by https://stackoverflow.com/a/68814418/1319998 | |
from contextlib import contextmanager | |
from collections import namedtuple | |
from ctypes import cdll, byref, string_at, c_char_p, c_int, c_double, c_int64, c_void_p | |
from sys import platform | |
def query(db_file, sql, params=()): | |
libsqlite3 = cdll.LoadLibrary({'linux': 'libsqlite3.so', 'darwin': 'libsqlite3.dylib'}[platform]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension | UTI | preferred_extension | MIME_type | |
---|---|---|---|---|
c | public.c-source | c | None | |
f | public.fortran-source | f | None | |
h | public.c-header | h | None | |
i | public.c-source.preprocessed | i | None | |
l | public.lex-source | l | None | |
m | public.objective-c-source | m | None | |
o | public.object-code | o | None | |
r | com.apple.rez-source | r | None | |
s | public.assembly-source | s | None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Read adjustments data for photos edited in Apple's Photos.app | |
In Catalina and Big Sur, the adjustments data (data about edits done to the photo) | |
is stored in a plist file in | |
~/Pictures/Photos Library.photoslibrary/resources/renders/X/UUID.plist | |
where X is first character of the photo's UUID string and UUID is the full UUID, | |
e.g.: ~/Pictures/Photos Library.photoslibrary/resources/renders/3/30362C1D-192F-4CCD-9A2A-968F436DC0DE.plist | |
Thanks to @neilpa who figured out how to decode this information: | |
Reference: https://github.com/neilpa/photohack/issues/4 | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Proof of concept showing how to merge Apple Photos libraries including most of the metadata """ | |
# Currently working: | |
# * places photos into correct albums and folder structure | |
# * sets title, description, keywords, location | |
# Limitations: | |
# * doesn't currently handle Live Photos or RAW+JPEG pairs | |
# * only merges the most recent version of the photo (edit history is lost) | |
# * very limited error handling | |
# * doesn't merge Person In Image |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Use Apple's Vision Framework via PyObjC to detect text in images | |
To use: | |
python3 -m pip install pyobjc-core pyobjc-framework-Quartz pyobjc-framework-Vision wurlitzer | |
""" | |
import pathlib |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" Create and mount a temporary disk image on MacOS """ | |
import pathlib | |
import platform | |
import subprocess | |
import tempfile | |
import time | |
class TempDiskImage: |