Skip to content

Instantly share code, notes, and snippets.

import Foundation
// MARK: - Extensions
extension URL {
var isDirectory: Bool {
(try? resourceValues(forKeys: [.isDirectoryKey]))?.isDirectory == true
}
}
@angry-boss
angry-boss / CoreML Image Recognition.py
Created November 16, 2025 11:20 — forked from omz/CoreML Image Recognition.py
CoreML Image Recognition.py
#!python3
'''
This is a demo of how you can use the CoreML framework (via objc_util) to classify images in Pythonista. It downloads the trained 'MobileNet' CoreML model from the Internet, and uses it to classify images that are either taken with the camera, or picked from the photo library.
'''
import requests
import os
import io
import photos
import dialogs
@angry-boss
angry-boss / DownloadPhotosFromCloud.py
Created November 16, 2025 11:20 — forked from omz/DownloadPhotosFromCloud.py
DownloadPhotosFromCloud.py
# Quick workaround for photos module (Pythonista) not downloading photos from iCloud
import photos
from objc_util import ObjCClass, ObjCInstance, ObjCBlock
def download_cloud_asset(asset):
PHImageManager = ObjCClass('PHImageManager')
PHImageRequestOptions = ObjCClass('PHImageRequestOptions')
ph_asset = ObjCInstance(asset)
ph_image_mgr = PHImageManager.defaultManager()
@angry-boss
angry-boss / core_image.py
Created November 16, 2025 11:20 — forked from omz/core_image.py
core_image.py
'''
This module provides a Python wrapper around CIImage and CIFilter for using CoreImage filters from Pythonista more easily.
How to use:
1) Create a CImage object. The constructor accepts either a file path, a ui.Image, PIL.Image.Image, or photos.Asset object. Example:
>>> # From a photo:
>>> img = CImage(photos.pick_asset())
>>> # From a ui.Image:
@angry-boss
angry-boss / UI Debugging Overlay.py
Created November 16, 2025 11:19 — forked from omz/UI Debugging Overlay.py
UI Debugging Overlay.py
# Pythonista script to show the UI Debugging overlay (private API) described in this blog post:
# http://ryanipete.com/blog/ios/swift/objective-c/uidebugginginformationoverlay/
from objc_util import ObjCClass, on_main_thread
UIDebuggingInformationOverlay = ObjCClass('UIDebuggingInformationOverlay')
@on_main_thread
def toggle_overlay():
UIDebuggingInformationOverlay.prepareDebuggingOverlay()
UIDebuggingInformationOverlay.overlay().toggleVisibility()
@angry-boss
angry-boss / motion.py
Created November 16, 2025 11:19 — forked from omz/motion.py
# `motion` module from Pythonista
# This is missing in the current App Store versions (in Pythonista 3.x, it's only missing in Python 2 mode).
# As a temporary workaround, you can put this file in the "site-packages" folder (under "Modules" or "Modules & Templates").
import _motion
shared_manager = _motion.MotionManager()
def start_updates():
shared_manager.start()
@angry-boss
angry-boss / photopicker2.py
Created November 16, 2025 11:18 — forked from omz/photopicker2.py
photopicker2.py
# Experimental photo picker using the Photos framework via objc_util. Compared to the photos module, this has the advantage of showing all photos, including iCloud photo library. Not very well tested!
from objc_util import *
import threading
from io import BytesIO
from PIL import Image
import sys
import ui
import ctypes
@angry-boss
angry-boss / Spellcheck word.py
Created November 16, 2025 11:17 — forked from omz/Spellcheck word.py
Spellcheck word.py
# coding: utf-8
from objc_util import ObjCClass
UITextChecker = ObjCClass('UITextChecker')
def check_word(word, lang='en_US'):
c = UITextChecker.new().autorelease()
check = c.rangeOfMisspelledWordInString_range_startingAt_wrap_language_
misspelled_range = check(word, (0, len(word)), 0, False, lang)
return (misspelled_range.location != 0)
@angry-boss
angry-boss / Check dictionary word.py
Created November 16, 2025 11:17 — forked from omz/Check dictionary word.py
Check dictionary word.py
# coding: utf-8
'''
Demo of using the built-in iOS dictionary to check words
NOTES: This is quite slow, it might be possible to use the spell-checking
dictionary for this instead, haven't tried that yet.
If no dictionary is downloaded yet, the API will always return True
(probably so that the "Define" menu item can be shown before
a dictionary has been downloaded).
'''
@angry-boss
angry-boss / EmbedPyui.py
Created November 16, 2025 11:17 — forked from omz/EmbedPyui.py
EmbedPyui.py
# coding: utf-8
'''
This is a little helper script to make it easier
to create single-file scripts with Pythonista, while
still taking advantage of the UI editor.
It'll essentially convert the .pyui file to a compact
string representation that you can embed directly
in your script. The code to unpack and load the UI
is also auto-generated for convenience.