This file contains 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 your "Saved Stories" articles from Apple News | |
Thanks to Dave Bullock (https://github.com/eecue) who's idea this was and who wrote the extract_info_from_apple_news function | |
This script requires the following modules be pip installed: | |
* bs4 | |
* requests | |
Save this script to a file called news.py and run it with Python 3.9 or later |
This file contains 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/bash | |
# Simple script to open the macOS Finder's "Info Window" for a file or folder. | |
# Usage: finfo [file or folder] | |
# This relies on realpath being installed (brew install coreutils) | |
if [ -z "$1" ]; then | |
echo "Usage: finfo [file or folder]" | |
exit 1 |
This file contains 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
"""Set metadata on macOS files using undocumented function MDItemSetAttribute | |
Background: Apple provides MDItemCopyAttribute to get metadata from files: | |
https://developer.apple.com/documentation/coreservices/1427080-mditemcopyattribute?language=objc | |
but does not provide a documented way to set file metadata. | |
This script shows how to use the undocumented function MDItemSetAttribute to do so. | |
`pip install pyobjc` to install the required Python<-->Objective C bridge package. |
This file contains 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
"""Uses CoreImage API via PyObjC to detect QR Codes in images on MacOS. | |
This is a simple wrapper around the CIDetector API and only returns the text of the QR Code. | |
It does not return the location of the QR Code in the image. | |
Reference: https://developer.apple.com/documentation/coreimage/cidetector/detector_types?language=objc | |
""" | |
from typing import List |
This file contains 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
"""Simple decorator that applies f-string formatting to docstrings | |
To use, simply apply `@fmydocstring` to your function | |
Only global variables are accessible for interpolation. | |
""" | |
import functools | |
This file contains 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 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 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 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 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]) |