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/bash | |
# Change symlink to Python version in /usr/local/bin/python to point to a | |
# specified version as installed by the official python.org installer for macOS | |
# usage: ./pyver.sh <version> | |
# when called without arguments, prints the currently linked Python version | |
# This is useful for use with pyenv (https://github.com/pyenv/pyenv) which can only | |
# handle a single "system" python version and offers no way to switch between multiple | |
# system pythons |
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
"""Copy a file on macOS using native API. | |
This allows copied files to use copy-on-write when used on a volume formatted with APFS. | |
When used on an APFS volume, a file copied with this function will be copied almost instantly | |
and will not use any additional disk space until the file is modified. | |
To use, you will need to install pyobjc-core and pyobjc-framework-Cocoa: | |
`python3 -m pip install pyobjc-core pyobjc-framework-Cocoa` |
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
"""Count photos for a given query criteria""" | |
from __future__ import annotations | |
import osxphotos | |
from osxphotos.cli import query_command | |
@query_command | |
def count_photos(photos: list[osxphotos.PhotoInfo], **kwargs): |
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
"""Redirect output of a command to a tkinter text box in real-time""" | |
from __future__ import annotations | |
import subprocess | |
import threading | |
import tkinter as tk | |
def update_text_box(text_box: tk.Text, proc: subprocess.Popen): |
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
"""Rescue lost Apple Notes notes, reference: https://fosstodon.org/@[email protected]/109992039449199371 | |
To run this: | |
1. Install python (I recommend the latest version of python 3 from python.org) | |
2. Install the dependencies: python3 -m pip install bpylist2 | |
3. Run the script: python3 noterescue.py <path to note file(s)> | |
The extracted files will be saved in the parent directory of the note file. |
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 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 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/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 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
"""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 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
"""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 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
"""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 | |