Skip to content

Instantly share code, notes, and snippets.

@chockenberry
Last active October 6, 2023 12:23
Show Gist options
  • Save chockenberry/d33ef5b6e6da4a3e4aa9b07b093d3c23 to your computer and use it in GitHub Desktop.
Save chockenberry/d33ef5b6e6da4a3e4aa9b07b093d3c23 to your computer and use it in GitHub Desktop.
A shell script for Tot
#!/bin/sh
basename=`basename $0`
if [ -z "$*" ]; then
echo "usage: ${basename} <dot> [ -o | -r | <file> | - ]"
echo ""
echo "options:"
echo " -o open dot in window with keyboard focus"
echo " -r read contents of dot"
echo " -c clear contents of dot"
echo " <file> append contents of regular file to dot"
echo " - append standard input to dot"
echo ""
echo "examples:"
echo " $ cal -h | tot 1 - # put a calendar in first dot"
echo " $ tot 2 MyApp.crash # put a crash report in second dot"
echo ""
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
@zrzka
Copy link

zrzka commented Feb 28, 2020

Nit - usage & examples - tot should be tot.sh in this case -> ${basename}.

@tadpol
Copy link

tadpol commented Mar 23, 2020

Curious as to why using osascript -e "tell application \"Tot\" to open location \"tot://${dot}/append?text=${text}\"" instead of open "tot://${dot}/append?text=${text}"

@neilio
Copy link

neilio commented Apr 1, 2020

I have an issue where the flags don't seem to be recognized. When I try commands like "tot -o 1" or "tot -r 3" I get the "not a regular file" error. Any ideas for how to fix this?

@chrisgrieser
Copy link

Is it possible to determine which dot is the currently open one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment