Occasionally I leave my computer unsuspended when I need to go somewhere but I am leaving it with people I absolutely trust and I will be back shortly so no real need to suspend (like if it's family and I'm just popping to the loo which is only a small distance away from where I am and you know, it's not convenient to always suspend my machine when it's like this), or there may be other reasons why I want this, like to know if I should run to my machine to wiggle the mouse before it goes to sleep, or if I can go to my computer at a slower pace.
Anyway, to get to the point, I would like to be able to launch a countdown (preferably in a see-through (the see-through bit is not a must) window on top of everything in the top right hand corner of my screen just below the top bar) display which will show me a countdown to the next suspend time.
This could either reset the timer every time I interact with the machine or somehow directly interface with the suspend system to tell when the next suspend is (because I assume that there is some sort of countdown). How could something like this be achieved (of course I would not want the window to always be open but instead for me to be able to run a command any time that would start the window, or it could even be a countdown in a Terminal window that I would just move or would automatically be located in the top right hand corner if the GUI bit is at all problematic)?
I am running Ubuntu GNOME 15.10 with GNOME 3.18 but the solution should also work with Ubuntu GNOME 16.04 with GNOME 3.20 as I plan to upgrade soon.
Best Answer
EDIT
In the original answer, further below, the countdown window appeared after an arbitrary idle time. Re- reading your question, you might want it permanently. The permanent version is below (which is simpler), the original answer further down.
1a. Version, permanently showing countdown time
The solution is a background script, showing a semi- transparent countdown window. The window behaves like a notification: it is always visible on top, but (of course) you can work in your other windows as usual:
The initial time is the idle- time before suspend should be activated. The time is reset on mouse- keyboard events.
As the image shows, the script comes with different pre- set color options (see further below).
How to setup
The script needs
xprintidle
:countdown.py
Run it with the idle time as argument:
e.g.
to enter suspend after 5 minutes.
If all works fine, add it to startup applications: Dash > Startup Applications > Add. Add the command:
The script
Note
The text color can be changed, as explained at the very bottom of the second version of the answer.
1b. As requested in a comment: luxury version of the same script: text color changes to yellow if half the time passed, to red 30 seconds before suspend.
> >
Use it exactly as
1a
.The script
2. Original answer: version, showing countdown time after x idle time
The setup below will show a countdown (during an arbitrary time length) to the next suspend:
The window is always on top of all other windows, exactly like the notification bubbles.
The setup replaces the "normal" suspend settings, which means you need to disable suspend from system settings.
About the solution
The command to suspend in the script is:
which doesn't require
sudo
. The consequence is that you will need at least15.04
to use this solution.The script was written and tested on
Ubuntu
(Unity)15.10
, but there is no specific code in it that should be Unity specific. I assume it works fine on all default Ubuntu versions >15.04
How it works
To setup (detailed version further below), simply copy the three scripts involved into one and the same directory, exactly named as indicated. To run, simply run the main script (running the time- check).
How to setup
The script needs
xprintidle
:Copy the three scripts below into separate empty files, save the in one and the same directory, exactly named as indicated:
A. save (exactly) as
win.py
:B. Save exactly as
runner.py
:C. Save (exactly) as
susp.sh
:Make all three scripts executable, and again, make sure they are in one and the same directory.
You're practically done.
Test- run the script the suspend time (idle time before suspend should be applied), and the count down time (in seconds) as arguments, e.g.:
to set idle time to 10 minutes, counter starts 5 minutes before suspend.
If all works fine, add it to startup applications: Dash > Startup Applications > Add. Add the command:
Notes
In the head section of the
win.py
, you can set different colors for the displayed text:Playing with the values in the lines:
and
(from the function
get_screen
, where 200 is the distance of the left side of the window to the right side of the screen), and(where 35 is the distance between the window and the top of the screen), you can easily change the geometry of the window, e.g.:
Have fun :)