Skip to content

Instantly share code, notes, and snippets.

@hiilppp
hiilppp / sort.py
Last active February 8, 2019 13:02
Python script to sort lines of text in Pythonista and send them (back) to Drafts.
# To call script from Drafts, use the follwing URL as URL Action:
# <pythonista://sort?action=run&argv=[[draft]]>
import sys
import urllib
import webbrowser
a = sys.argv[1].split("\n")
a.sort(key=str.lower)
a = "\n".join(a)
@hiilppp
hiilppp / calculate.py
Created December 6, 2013 11:42
Python script to calculate arithmetic expressions in Pythonista and send them, along with their results, (back) to Drafts.
# To call script from Drafts, use the follwing URL as URL Action:
# <pythonista://calculate.py?action=run&argv=[[draft]]>
# Except for the last ten lines, this script was written by Erez Shinan, see <http://erezsh.wordpress.com/2013/02/24/how-to-write-a-calculator-in-70-python-lines-by-writing-a-recursive-descent-parser/>.
'''A Calculator Implemented With A Top-Down, Recursive-Descent Parser'''
# Author: Erez Shinan, Dec 2012
import re, collections, sys
from operator import add,sub,mul,div
@hiilppp
hiilppp / list.py
Created December 10, 2013 01:11
Python script to manipulate text in Pythonista in the following manner and send the result (back) to Drafts: Sort lines, remove blank and duplicate lines, and prepend a hyphen to lines which don't start with one.
# To call script from Drafts, use the follwing URL as URL Action:
# <pythonista://list.py?action=run&argv=[[draft]]>
import os
import re
import sys
import urllib
import webbrowser
a = re.sub(r"(?m)^[*-] ", "", sys.argv[1])
@hiilppp
hiilppp / redirect_to_pythonista.html
Created January 4, 2014 14:23
HTML file that opens Pythonista, where a specified script is executed, while the browser window closes in the background. This serves as workaround for IFTTT's lack of support for custom URL schemes in the URL parameter of Pushover's Channel.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; pythonista://foo.py&action=run&argv=bar"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script language="JavaScript">
setTimeout("self.close()", 500);
</script>
</head>
@hiilppp
hiilppp / insert_location.py
Created January 5, 2014 14:27
Python script to append the current location (either as address or Google Maps link) to the provided text (which may be "") in Pythonista and send the result (back) to Drafts.
# -*- coding: utf-8 -*-
# To call script from Drafts, use the follwing URLs as URL Actions:
# - <pythonista://insert_location.py?action=run&argv=[[draft]]&argv=address>
# (Will insert the address of your current location.)
# - <pythonista://insert_location.py?action=run&argv=[[draft]]&argv=link>
# (Will insert a Google Maps link to your current location.)
import location
import re
@hiilppp
hiilppp / urlschemes.sh
Created February 20, 2014 18:14
Shell script to list the URL schemes associated with apps installed on your Mac.
#!/bin/sh
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -dump | grep -E "^[[:space:]]*bindings:.+[a-z]+[a-z0-9.+-]*:" | sed -E "s/^[[:space:]]*bindings:[[:space:]]+//" | sort -u
@hiilppp
hiilppp / random_reminders.py
Created April 2, 2014 15:03
Pythonista script that randomly selects a reminder (out of a given list) and schedules a (quiet) notification for that reminder at a random point of time in the future (within a given range). Opening the notification will then schedule a new reminder notification (and, if provided, follow a link).
import notification
from random import randint
import sys
import urllib
import webbrowser
reminders = ["Reminder A", ["Reminder B", "url://"], "Reminder C"]
n = randint(0, len(reminders)-1)
URL = "pythonista://random_reminders.py?action=run"
@hiilppp
hiilppp / leaving_range.scpt
Created April 16, 2014 19:19
AppleScript to lock your Mac's screen, pause iTunes (if playing), and sync OmniFocus (if open). (Use EventScripts to automatically trigger script when a Bluetooth device (e.g., your iPhone) leaves your Mac's range: http://www.mousedown.net/mouseware/EventScripts.html)
do shell script "defaults write com.apple.screensaver askForPassword 1; defaults write com.apple.screensaver askForPasswordDelay 0"
repeat until (do shell script "defaults read com.apple.screensaver askForPassword") = "1" and (do shell script "defaults read com.apple.screensaver askForPasswordDelay") = "0"
delay 0.5
end repeat
tell application "ScreenSaverEngine" to activate
if application "iTunes" is running then
tell application "iTunes"
@hiilppp
hiilppp / entering_range.scpt
Created April 16, 2014 19:20
AppleScript to unlock your Mac's screen. (Use EventScripts to automatically trigger script when a Bluetooth device (e.g., your iPhone) enters your Mac's range: http://www.mousedown.net/mouseware/EventScripts.html)
-- You need to create a Keychain item whose name matches what you use in place
-- of "[keychain_item_name]" on line #7 (and whose password is identical to your
-- user account's password).
tell application "System Events"
if ((get name of every process) contains "ScreenSaverEngine") then
set pw to (do shell script "security find-generic-password -l \"[keychain_item_name]\" -w")
tell application "ScreenSaverEngine" to quit
delay 0.5
keystroke pw
@hiilppp
hiilppp / tf2cp.scpt
Created April 17, 2014 09:28
AppleScript that places the content of a text file on the clipboard as the file is added to a directory to which this script is associated as Folder Action. (Can be used to send text from your iOS device to your Mac's clipboard via Dropbox.)
on truncate(a, n)
set a_2 to paragraph 1 of a
set text_item_delimiters to text item delimiters
set text item delimiters to space
set a_2_text_items to text items of a_2
set text item delimiters to text_item_delimiters
set NO_paragraphs_in_a to count paragraphs of a
if (count text items of a_2_text_items) > n then
set text_item_delimiters to text item delimiters
set text item delimiters to space