diff --git a/tools/README.macos b/tools/README.macos new file mode 100644 index 0000000..c3a657d --- /dev/null +++ b/tools/README.macos @@ -0,0 +1,55 @@ +# Collection of tools for the reMarkable paper tablet + +# MacOS instructions: + +1. Install MacPorts + +The following binaries are required running these tools: + + * python3 + * imagemagick + * pdftk + * librsvg + +Once MacPorts is installed, the following two commands should install all requirements: + + sudo port install python36 imagemagick librsvg pdftk + sudo port select --set python3 python36 + +## The rest of the README file is unchanged from here on: + +## rM2svg + +Convert a .lines file to an svg file + + usage: rM2svn [-h] -i FILENAME -o NAME + + optional arguments: + -h, --help show this help message and exit + -i FILENAME, --input FILENAME .lines input file + -o NAME, --output NAME prefix for output file + --version show program's version number and exit + +## exportNotebook + +Convert a Notebook to a PDF file: Searches for the most recent Notebook whose +visible name contains NAME, and exports it as PDF file. Works also for +(annotated PDF files). + + usage: exportNotebook NAME + + $ exportNotebook Jour + Exporting notebook "Journal" (4 pages) + Journal.pdf + +### SSH configuration + +The `exportNotebook` script assumes a USB connection. If you are connected via +WiFi, you can add an entry to your `~/.ssh/config`: + + host remarkable + # adapt IP if necessary + Hostname 10.11.99.1 + User root + ForwardX11 no + ForwardAgent no diff --git a/tools/exportNotebook b/tools/exportNotebook index d6ac523..953a261 100755 --- a/tools/exportNotebook +++ b/tools/exportNotebook @@ -1,11 +1,17 @@ #!/usr/bin/env bash -# Needs: +# Linux Needs: # - ssh and scp (openssh) # - convert (imagemagick) # - pdftk (pdftk) # - rsvg-convert (optional, to avoid rasterizing of lines) # - gs & pdfinfo (optional, to account for original pdf size) +# +# MacOS Needs: (see README.macos) +# - python3 +# - convert (imagemagick) +# - pdftk +# - librsvg if [[ $# -eq 0 ]] ; then echo "Usage: ./exportNotebook (Partial)NotebookName AdditionalrM2svgArguments" @@ -14,16 +20,12 @@ if [[ $# -eq 0 ]] ; then fi # Make sure we have rM2svg -command -v rM2svg >/dev/null 2>&1 +command -v ./rM2svg >/dev/null 2>&1 if [[ $? -ne 0 ]]; then - if [[ -x rM2svg ]]; then - rM2svg_cmd="$(dirname `readlink -f $0`)/rM2svg" - else - print "Cannot find rM2svg" - exit 1 - fi + print "Cannot find ./rM2svg" + exit 1 else - rM2svg_cmd="rM2svg" + rM2svg_cmd="./rM2svg" fi # Check if ssh configuration for "remarkable" exists @@ -35,10 +37,12 @@ else fi # Start SSH in ControlMaster mode -control_path_dir=$(mktemp -d --suffix=ssh_remark) +control_path_dir=$(mktemp -d) control_options="-o ControlPath=$control_path_dir/%h_%p_%r -o ControlPersist=10s" ssh -M ${control_options} ${SSH_IP} exit +echo "Getting notebook prefix" + # Getting the notebook prefix (Newest notebook matching the name) id=$(ssh ${control_options} ${SSH_IP} "ls -rt .local/share/remarkable/xochitl/*.metadata | xargs fgrep -l $1" | tail -n1 | cut -d. -f1,2) @@ -46,6 +50,9 @@ test -z "$id" && exit 1 tmpfolder=$(mktemp -d) +echo "Notebook prefix obtained" + + # Getting notebook data scp $control_options -q ${SSH_IP}:"${id}".{lines,pagedata,metadata} "${tmpfolder}"/ @@ -62,7 +69,7 @@ fi sed -i -e "s/^[[:blank:]]*$/Blank/" "${tmpfolder}"/*.pagedata filename=$(grep -F '"visibleName"' "${tmpfolder}"/*.metadata | cut -d: -f2- | grep -o '"[^"]*"') -echo "Exporting notebook ${filename} ($(wc -l "${tmpfolder}"/*.pagedata | cut -d\ -f1) pages)" +echo "Exporting notebook ${filename} ($(ls -1 "${tmpfolder}"/*.pagedata | wc -l | awk '{print $1}') pages)" if [ -f "${tmpfolder}"/*.pdf ] then @@ -115,10 +122,13 @@ fi # Strip .pdf suffix if it already exists (document vs. notebook) filename=$(basename -s .pdf ${filename//\"/}) +# Destroy all special characters +filename=`echo $filename | tr -dc '[:print:]\n\r'` + # Use multistamp instead of multibackground to preserve transparency pdftk "${tmpfolder}"/background.pdf multistamp "${tmpfolder}"/foreground.pdf output "${filename}.pdf" -filesize=$(ls -la "${filename}.pdf" | awk '{print $5}' | numfmt --to=iec-i --suffix=B --format="%.3f") +filesize=$(ls -lah "${filename}.pdf" | awk '{print $5}' ) echo "Written ${filesize} to ${filename}.pdf" ssh $control_options -O exit ${SSH_IP}