Quantcast
Channel: MobileRead Forums - PocketBook
Viewing all articles
Browse latest Browse all 1245

Live UI feedback in a "sleep timer" bash script for PocketBook

$
0
0
Hi,

I am trying to code my very first PocketBook bash script. I wanted a little tool to send the device to "sleep" (which is no real sleep, but a simple reboot) after a certain amount of time (so that I could e.g. listen to audiobooks and the playback would be stopped at some point automatically).

This is what I came up with so far:

Code:

#!/bin/sh

SH_IVTOOL=/mnt/ext1/applications/sh_ivtool.app

sleep_time=`$SH_IVTOOL -n "Enter sleep in time in mins (or leave empty to cancel):"`
# workaround to strip away trailing "latinime: Loading /ebrmain/share/latinime//EN.dict" string
sleep_time=${sleep_time:51}

if [ $? -eq 0 ]; then
        while [[ $sleep_time -ne 0 ]]; do
                sleep 60
                sleep_time=$((sleep_time-1))
        done
        iv2sh reboot
fi

exit 0

So far this works on my PB Verse Pro. To make it a bit prettier, I was wondering if I could show the minutes left until the device goes to sleep on the screen (and, ideally, add some extend and cancel button). I suppose a bash script is not really supposed for this kind of work, but I will most certainly not start to learn C for this :D

I tried to do something like this in the loop, but it did not seem to work stably:

Code:

        while [[ $sleep_time -ne 0 ]]; do
                $SH_IVTOOL -s "Will go to sleep in $sleep_time mins $pid" &
                pid=$!
                sleep 2 # 2 seconds for testing purposes
                iv2sh SendEventTo -9 "$pid"
                sleep_time=$((sleep_time-1))
        done

Do you have any other ideas?

Viewing all articles
Browse latest Browse all 1245

Trending Articles