Skip to content

Instantly share code, notes, and snippets.

View tk512's full-sized avatar

Torbjørn Kristoffersen tk512

  • Stellenbosch, South Africa
View GitHub Profile
@tk512
tk512 / cached_token.py
Created November 4, 2019 13:19
Simple JSON file cache to retrieve e.g. a token
import os
import json
def cached_token(jsonfile):
def has_valid_token(data):
return 'token' in data
def get_token_from_file():
with open(jsonfile) as f:
data = json.load(f)
#!/bin/sh
# Can be used by your scripts to send iMessages from the shell
# Usage:
# ./SendMessage.sh 1234567890 'hi there!'
recipient="${1}"
message="${*:2}"
cat<<EOF | osascript - "${recipient}" "${message}"
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
# Event handler
using terms from application "Messages"
on message received theText from theBuddy for theChat
set quoted_message to quoted form of theText
set quoted_id to quoted form of (id of theBuddy as text)
do shell script "echo " & quoted_message & " | ~/bin/MessageReceive.sh " & quoted_id & " > /dev/null 2>&1 &"
# make messages happy
return true
end message received