#!/bin/sh
basename=basename $0
if [ -z "$*" ]; then
echo "usage: ${basename}
dot="\(1"
if [ -z "$2" ]; then
echo "error: no dot action specified"
exit 1
else
if [ "$2" = "-o" ]; then
# open dot
osascript -e "tell application \"Tot\" to open location \"tot://\){dot}""
osascript -e "tell application "Tot" to activate"
elif [ "$2" = "-r" ]; then
# get contents of dot
osascript -e "tell application "Tot" to open location "tot://\({dot}/content\""
elif [ "$2" = "-c" ]; then
# clear contents of dot
osascript -e "tell application \"Tot\" to open location \"tot://\){dot}/replace?text=""
else
# append file or stdin to dot
if [ "$2" = "-" ]; then
FILE=mktemp -t ${basename}
|| exit 1
cat /dev/stdin > $FILE
else
if [ -f "$2" ]; then
FILE="$2"
else
echo "error: not a regular file"
exit 1
fi
fi
text=`cat $FILE | python -c 'import urllib; import sys; print urllib.quote(sys.stdin.read())'`
osascript -e "tell application \"Tot\" to open location \"tot://${dot}/append?text=${text}\""
fi
fi