Skip to content

Instantly share code, notes, and snippets.

@mavcunha
Forked from chockenberry/tot.sh
Last active June 25, 2020 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mavcunha/f033f14a1add66e0d8e84ffa62e6f195 to your computer and use it in GitHub Desktop.
Save mavcunha/f033f14a1add66e0d8e84ffa62e6f195 to your computer and use it in GitHub Desktop.
A shell script for Tot
#!/bin/sh
basename=`basename $0`
if [ -z "$*" ]; then
cat <<-EOH
usage: ${basename} <dot> [ -o | -r | <file> | - ]
options:
-o open dot in window with keyboard focus
-r read contents of dot
-c clear contents of dot
<file> append contents of regular file to dot
- append standard input to dot
examples:
$ cal -h | tot 1 - # put a calendar in first dot
$ tot 2 MyApp.crash # put a crash report in second dot
EOH
exit 1
fi
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment