Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added MacOS support #16

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions tools/README.macos
Original file line number Diff line number Diff line change
@@ -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
34 changes: 22 additions & 12 deletions tools/exportNotebook
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -35,17 +37,22 @@ 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)

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}"/

Expand All @@ -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)"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ls does -1 automatically in a pipe so it's not needed here


if [ -f "${tmpfolder}"/*.pdf ]
then
Expand Down Expand Up @@ -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}
Expand Down