Skip to content

Instantly share code, notes, and snippets.

@kbauer
Last active August 28, 2022 16:02
Show Gist options
  • Save kbauer/69ff3f62c85f741958f4 to your computer and use it in GitHub Desktop.
Save kbauer/69ff3f62c85f741958f4 to your computer and use it in GitHub Desktop.
A companion script for the BoogieBoard Sync 9.7 eWriter. The main purpose is to put the latest Bluetooth-synced page into the clipboard as image data. Depends on the `imagemagick-scan-to-mono.sh` script (see https://gist.github.com/kbauer/e5bd0dc12142e7a6c97f).
#!/usr/bin/env bash
source libstacktrace || true
set -e -E -u
BOOGIEDIR="$(cygpath "$LOCALAPPDATA")/BoogieBoardSync/Downloads"
cd "$BOOGIEDIR"
MANUAL="
Usage: $0 --daemon
$0 --rebuild
$0 (-h | --help)
Builds png files for the pdf images downloaded from the boogieboard
into the directory
$BOOGIEDIR
and pushes the latest one to the clipboard. Uses two possible modes:
--daemon
Watch for new PDF files and convert them. Can be used to
instantly obtain the latest scribble in the clipboard.
--rebuild
Force rebuilding all PNG files.
-h, --help
Show this help text.
This script assumes that you have the BoogieBoard Virtual Desktop
Companion software (Windows, MacOS) installed and enabled automatic
download over Bluetooth.
If you run it through Wine, you may have to set the LOCALAPPDATA
environment variable to point to the 'C:/Users/USER/Appdata/Local'
directory.
"
main() {
if [[ $# = 0 ]]; then die 1 "$MANUAL"; fi
if ishelp "$1"; then die 0 "$MANUAL"; fi
if [[ $1 = --daemon ]]; then run_daemon; exit 0; fi
if [[ $1 = --rebuild ]]; then run_rebuild; exit 0; fi
die 2 "$MANUAL"
}
run_rebuild () {
for pdffile in *.PDF; do
do_convert_then_pushto_clipboard "$pdffile"
done
}
run_daemon () {
while true; do
for pdffile in *.PDF; do
if ! [[ -e $pdffile ]]; then
# Happens when *.PDF expand to literal *.PDF because no files exist yet.
break
elif ! [[ -e $(pngfile "$pdffile") ]]; then
do_convert_then_pushto_clipboard "$pdffile"
fi
done
sleep 1
done
}
do_convert_then_pushto_clipboard () {
local pdffile="$1"
local pngfile=$(pngfile "$pdffile")
convert -density 150 "pdf:$pdffile" "png:.tmp.png"
imagemagick-scan-to-mono.sh ".tmp.png"
rm ".tmp.png."*".bak" || true
mv ".tmp.png" "$pngfile"
printf "'%s' -> '%s'\n" "$pdffile" "$pngfile"
convert "png:$pngfile" -trim clipboard:myimage
}
pngfile () {
echo "${1%.*}.PNG"
}
ishelp(){
[[ $1 = -h ]] || [[ $1 = --help ]]
}
die() {
local exitstatus="$1"; shift 1
echo "$*"
exit "$exitstatus"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment