Skip to content

Instantly share code, notes, and snippets.

View nuclearsecrecy's full-sized avatar

Alex Wellerstein nuclearsecrecy

View GitHub Profile
@nuclearsecrecy
nuclearsecrecy / getElementByClassAndName.applescript
Last active August 8, 2024 15:36
Applescript function for finding specific UI elements in an application window by their name and (optionally) their class
# This is a function that will try to search a given set of elements for a
# matching class and name property. See above for example usage, where "Recognize..."
# is the name, `button` is the class (or `false` if you don't care about matching the class),
# and `entire contents` is the set of all UI elements to search. Sometimes elements don't have a
# name or class, which is why the try statement is in there.
# It returns "false" if the element was not found.
#
# This is not super fast, so it is probably best used to get a static reference,
# and not in a dynamic function. On my machine it takes maybe 4 seconds to search through
# 60 elements or so, 20ish seconds to search through 400 elements (not uncommon for a
@nuclearsecrecy
nuclearsecrecy / pdfexpert_batch_ocr.applescript
Last active December 16, 2024 19:20
Applescript to batch run OCR on many PDF files using PDF Expert
# Applescript to batch OCR PDFs using PDF Expert.
# By Alex Wellerstein. Last updated December 16, 2024. No copyright asserted -- released for public domain use.
# Absolutely no warranties, guarantees, promises, ANYTHING provided. Use at your own risk.
#
# Will automatically save and close each PDF after OCR completes.
# Assumes PDF Expert is the default program to open PDFs!
# Does not have robust error handling. Held together with duct tape.
# Just a temporary solution until Readdle actually supports batch operations.
# Seems to work on OS 14.6.1, with PDF Expert 3.10.10.
# Has not been extensively tested to see what happens if you try to do other work while it is running; could foul up.