Skip to content

Instantly share code, notes, and snippets.

@cobalamin
Last active February 17, 2019 21:11
Show Gist options
  • Save cobalamin/dbad27c9005e5b809d777c819bc31ed7 to your computer and use it in GitHub Desktop.
Save cobalamin/dbad27c9005e5b809d777c819bc31ed7 to your computer and use it in GitHub Desktop.
next_week.sh: a script for the reMarkable tablet to create a new page for my weekly planner suspend screen

Overview

Based (and improving) on: http://abcxyz.de/2017/12/07/turn-rms-suspended-screen-in-something-useful/, this device script makes it possible to keep all previous pages in the notebook you've created for your suspend screen. It does this by pushing all existing pages one "to the back" and generating a fresh one.

Dependencies

Setup

(All this must be done on the device).

  • Set up the dependencies

  • Create a notebook as described above, and open it on the device once, but keep it unchanged

  • Copy the initial empty 0.rm file to _empty.rm, the 0.png file to _empty.png, and the 0.jpg file to _empty.jpg in the folders <youruuid>/, <youruuid.cache>/, and <youruuid.thumbnails>, respectively.

  • Change TEMPLATE_NAME to suit your needs. Must refer to an existing template on your reMarkable tablet. (you can just use builtins like Blank if you don't want to set up an own one, just look at the names in the template overview.)

  • Change SUSPEND_SCREEN_UUID to the UUID that represents your suspend screen notebook (see the original blog post).

Usage

Whenever you want to create a new week/day/whatever, just run the script. There are no arguments.

#!/bin/bash
set -e
BASE_PATH="/home/root/.local/share/remarkable/xochitl"
TEMPLATE_NAME="S_Blk_screen"
SUSPEND_SCREEN_UUID="cb55aae3-6073-44a2-96ef-3f02e89d127e"
SUSPEND_SCREEN_PATH="$BASE_PATH/$SUSPEND_SCREEN_UUID"
systemctl stop xochitl
pushd $SUSPEND_SCREEN_PATH >/dev/null
function update_metadata {
jq '.version += 1 | .modified = true | .lastModified = "'`date +"%s000"`'"' $1.metadata > $1.metadata.tmp && cp $1.metadata.tmp $1.metadata
}
function update_content {
jq '.pageCount += 1' $1.content > $1.content.tmp && mv $1.content.tmp $1.content
}
function update_pagedata {
sed -i '1s;^;'"$TEMPLATE_NAME"'\n;' $1.pagedata
}
function increase_all_files {
pushd $1 >/dev/null
for file in `ls|sort -g -r`
do
filename=$(basename "$file")
extension=${filename##*.}
filename=${filename%.*}
if [ $filename -eq $filename ] 2>/dev/null
then
mv "$file" "$(($filename + 1))".$extension
fi
done
popd >/dev/null
}
# Move all relevant files "one to the right"
increase_all_files $SUSPEND_SCREEN_PATH
increase_all_files "$SUSPEND_SCREEN_PATH.cache"
increase_all_files "$SUSPEND_SCREEN_PATH.thumbnails"
# Create a new first page
cp "$SUSPEND_SCREEN_PATH/_empty.rm" "$SUSPEND_SCREEN_PATH/0.rm"
cp "$SUSPEND_SCREEN_PATH.cache/_empty.png" "$SUSPEND_SCREEN_PATH.cache/0.png"
cp "$SUSPEND_SCREEN_PATH.thumbnails/_empty.jpg" "$SUSPEND_SCREEN_PATH.thumbnails/0.jpg"
# Update .content and .metadata files
update_metadata $SUSPEND_SCREEN_PATH
update_content $SUSPEND_SCREEN_PATH
update_pagedata $SUSPEND_SCREEN_PATH
# Remove stuff I don't use for the suspend screen
rm -rf "$SUSPEND_SCREEN_PATH.highlights"
rm -rf "$SUSPEND_SCREEN_PATH.textconversion"
# Remove all page metadata, I don't use it for all I can tell
rm -f $SUSPEND_SCREEN_PATH/*-metadata.json
systemctl start xochitl
echo "Success. All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment