Skip to content

Instantly share code, notes, and snippets.

@jsbain
jsbain / add_action.py
Last active December 9, 2016 06:21
add_action.py
# coding: utf-8
'''
Manipulate action (wrench) menu
example:
add_action('/stash/launch_stash.py','monitor')
save_defaults() # so it is stored for next launch
'''
from objc_util import *
@jsbain
jsbain / canvas_save.py
Created January 24, 2016 07:44
canvas_save.py
# coding: utf-8
from objc_util import *
import canvas
import os
def save_canvas_to_png(filename):
rootVC = UIApplication.sharedApplication().keyWindow().rootViewController()
image=rootVC.accessoryViewController().consoleViewController().canvasImageView().image()
if image:
data=ObjCInstance(c.UIImagePNGRepresentation(image))
data.writeToFile_atomically_(os.path.abspath(filename),True)
@jsbain
jsbain / notificationplayground.py
Created January 25, 2016 18:32
notificationplayground.py
# coding: utf-8
#. objc from http://www.thinkandbuild.it/interactive-notifications-with-notification-actions/
from objc_util import *
UIUserNotificationSetting=ObjCClass('UIUserNotificationSettings')
#UIUserNotificationType=ObjCClass('UIUserNotificationType')
UIMutableUserNotificationCategory=ObjCClass('UIMutableUserNotificationCategory')
UIMutableUserNotificationAction=ObjCClass('UIMutableUserNotificationAction')
UIUserNotificationSettings=ObjCClass('UIUserNotificationSettings')
UILocalNotification=ObjCClass('UILocalNotification')
@jsbain
jsbain / notificationplayground.py
Created January 26, 2016 08:50
notificationplayground.py
# coding: utf-8
#. objc from http://www.thinkandbuild.it/interactive-notifications-with-notification-actions/
from objc_util import *
UIUserNotificationSetting = ObjCClass('UIUserNotificationSettings')
UIMutableUserNotificationCategory = ObjCClass('UIMutableUserNotificationCategory')
UIMutableUserNotificationAction = ObjCClass('UIMutableUserNotificationAction')
UIUserNotificationSettings = ObjCClass('UIUserNotificationSettings')
UILocalNotification = ObjCClass('UILocalNotification')
@jsbain
jsbain / togglelinenumbers.py
Created January 29, 2016 16:30
togglelinenumbers.py
# coding: utf-8
from objc_util import *
app=UIApplication.sharedApplication()
rootVC = app.keyWindow().rootViewController()
tabVC = rootVC.detailViewController()
tvc=tabVC.selectedTabViewController()
ed=tvc.editorView()
tv=ed.textView()
tv.showLineNumbers=not tv.showLineNumbers()
if tv.gutterView():
@jsbain
jsbain / pepline.py
Created April 18, 2016 06:15
pepline.py
#!python2
import editor, ui
import _editor_pythonista
from objc_util import *
@on_main_thread
def create_vertical_line(num_cols=80):
''' create vertical line at column index specified.
TODO: register for file change notifications, add to all tabs, etc. add ability to remove.
'''
@jsbain
jsbain / column_guide.py
Created April 18, 2016 06:17
column_guide.py
#!python2
import editor, ui
import _editor_pythonista
from objc_util import *
@on_main_thread
def create_column_guide(num_cols=80):
''' create vertical line at column index specified.
TODO: register for file change notifications, add to all tabs, etc. add ability to remove.
'''
@jsbain
jsbain / rtf.py
Created April 29, 2016 08:35
rtf.py
from objc_util import *
import ui
def save_text(tv,filename):
'''save the attributed text from tv to an rtf file (provide full path)'''
attribtxt=ObjCInstance(tv).attributedText()
data=attribtxt.RTFFromRange_documentAttributes_(NSRange(0,attribtxt.length()), None)
@jsbain
jsbain / scrape.py
Created May 8, 2016 17:36
scrape.py
#!python2
# coding: utf-8
import ui,requests, json, time, console, urllib
# create debuggin delegate code. not necessary, but helpful for debugging
debugjs='''
// debug_utils.js
// 1) custom console object
console = new Object();
console.log = function(log) {
@jsbain
jsbain / clk.py
Created May 11, 2016 17:48
clk.py
import ui,time
import bz2
from base64 import b64decode
import threading
import math
from objc_util import on_main_thread
#https://gist.github.com/b8e6f213d19e9d4668a7f28bbd1efe9f