Skip to content

Instantly share code, notes, and snippets.

@kitschpatrol
kitschpatrol / apple-photos-export.applescript
Last active May 7, 2024 20:09
AppleScript to automate image export from Apple Photos
-- Export images from Photos via automated GUI manipulation
-- It's an unsavory approach, but no other means of automation seems to yield higher quality edited image exports (so far)
-- Arguments are passed in their order of appearance in the GUI, and expect values exactly matching the UI strings in Photos.app
-- Accepts an individual photo UUID, or an album UUID (use osxphotos query to look up UUIDs)
on run { uuid, exportDirectory, photoKind, jpegQuality, tiffBitDepth, colorProfile, photoSize, maxSizeType, maxSizeValue, includeMetadata, includeLocation , fileName, sequentialPrefix, subfolderFormat}
tell application "System Events"
set wasRunning to (name of processes) contains "Photos"
end tell
sudo dtrace -n 'objc$target::*:* { @[probefunc] = count(); } tick-5sec { exit(0); }' -p `pgrep -x Photos`
@kitschpatrol
kitschpatrol / photos-album-exporter.swift
Created April 19, 2024 05:28
Minimum viable Apple Photos library image export
import Foundation
import Cocoa
import Photos
class PhotoExporter {
let imageManager = PHImageManager.default()
func exportPhoto(withLocalIdentifier identifier: String, to destinationURL: URL) {
// Fetch the asset with the specified identifier
<script is:inline>
(() => {
const key = 'sl-sidebar-state';
let savedState;
const savedStateJson = sessionStorage.getItem(key);
if (savedStateJson) {
try {
savedState = JSON.parse(savedStateJson);
@kitschpatrol
kitschpatrol / fractions.swift
Last active October 10, 2019 17:30
Turn a decimal number into a fractional approximation rounded to a maximum denominator
import Foundation
import UIKit
// Turn a decimal number into a fractional approximation rounded to a maximum denominator
// https://github.com/jadengeller/fractional?
// https://stackoverflow.com/questions/35895154/decimal-to-fraction-conversion-in-swift#35895607
typealias Rational = (whole: Int, numerator: Int, denominator: Int)
func decimalToRational(of value: Double, withDenominator denominator: Int) -> Rational {
#!/usr/bin/python
# Script to automate downloading CSV files from GoogleDocs into the lens asset folders
# Note that google broke password authentication in April 2015, so the interface changed slightly
# to use the oauth-supporting library gspread.
#
# Expects a Google oauth key file named google_oauth_key.json, created and downloaded
# from http://console.developers.google.com
#
# Usage example:
// Quick sketch to log brain data to a CSV
// Untested!!!
// Based on https://github.com/kitschpatrol/BrainGrapher
// Expects data from https://github.com/kitschpatrol/Brain
// Eric Mika Spring 2018
import processing.serial.*;
Serial serial;
Table table;
@kitschpatrol
kitschpatrol / BrainToOsc.pde
Last active January 18, 2018 05:58
Mindflex --> Arduino --> Processing --> OSC --> PD
// Mindflex --> Arduino --> Processing --> OSC --> PD
// Eric Mika Jan 2018
import processing.serial.*;
import netP5.*;
import oscP5.*;
Serial serial;
OscP5 oscProcessing;
NetAddress oscPD;
int frame = 0;
int wallOffset = 0;
final int windowWidth = 1;
final int wallWidth = 4;
boolean isDrawWallEnabled = false;
boolean isWallAnimated = true;
PImage pattern;
void setup() {
cloudy blue #acc2d9
dark pastel green #56ae57
dust #b2996e
electric lime #a8ff04
fresh green #69d84f
light eggplant #894585
nasty green #70b23f
really light blue #d4ffff
tea #65ab7c
warm purple #952e8f