Skip to content

Instantly share code, notes, and snippets.

@omz
omz / File Picker.py
Created February 22, 2016 03:14
File Picker.py
# coding: utf-8
import ui
import os
from objc_util import ObjCInstance, ObjCClass
from operator import attrgetter
import time
import threading
import functools
import ftplib
import re
@omz
omz / DownloadPhotosFromCloud.py
Created April 4, 2018 15:45
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()
@omz
omz / Top Apps.py
Created November 7, 2012 20:54
Top Apps
# Shows a list of the 10 top paid apps on the App Store.
print 'Loading...'
import feedparser
import console
print 'Fetching Feed...'
feed = feedparser.parse('http://itunes.apple.com/us/rss/toppaidapplications/limit=10/xml')
entries = feed['entries']
@omz
omz / ShortURL.py
Created May 17, 2013 04:17
ShortURL
# Simple URL shortener using is.gd
#
# Save this script as 'ShortURL' in Pythonista and add the
# bookmarklet below to Safari. The result is copied to the clipboard.
# Bookmarklet:
# javascript:window.location.href='pythonista://ShortURL?action=run&argv='+encodeURIComponent(window.location.href);
import clipboard
import re
@omz
omz / Add Playground Page.py
Created June 17, 2016 00:27
Add Playground Page.py
#! python3
# Share sheet extension script for adding new pages to Swift Playgrounds (experimental)
# HOW TO USE:
# 1. Add this script as a shortcut to the Pythonista extension (either from Pythonista's settings or the share sheet extension itself)
# 2. Tap the "Share" button in the Playground app's library.
# 3. Select the playground that you want to add a page to
# 4. Select "Run Pythonista Script" in the share sheet
# 5. Run this script, to select the chapter and page title.
@omz
omz / PythonistaBackup.py
Last active January 6, 2024 05:44
PythonistaBackup.py
# coding: utf-8
'''Creates a zip archive of your Pythonista files and serves them via HTTP in your local network.'''
import sys
if sys.version_info[0] >= 3:
from http.server import SimpleHTTPRequestHandler, HTTPServer
else:
from SimpleHTTPServer import SimpleHTTPRequestHandler
from BaseHTTPServer import HTTPServer
@omz
omz / UI Debugging Overlay.py
Last active January 6, 2024 05:44
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()
@omz
omz / Geotag Photos.py
Last active January 6, 2024 05:42
Geotag Photos.py
#!python3
'''
This is a proof-of-concept script for tagging photos with location data on iOS.
* First, it shows all photos that have no location data *and* are editable.
* Then, a grid of photos in temporal proximity is shown. You can pick multiple photos here.
* When you tap Done, the photo you selected first will get tagged with the average location of the photos you picked in the second step.
'''
import photos
@omz
omz / core_image.py
Last active January 6, 2024 05:42
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:
@omz
omz / Spellcheck word.py
Created March 10, 2016 20:01
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)