Page 1 of 1

Desktop icons for selective pc standby mode

Posted: Tue 05 May 2020, 18:06
by Fabio_hw
Hello, I would like to share something that, possibly, somebody else might find useful (or be willing to comment for improvement).

I created (Bionicpup64, running from usb stick) some desktop icons in order to enter selectively a standby mode on my laptop (according to various daily situations: short break, long standby, etc.) The icons are those visible in the attached screenshot (i.e., "sleep", "disk sleep" and "screen off")

The (very simple) code for each of them is:

1) For PC standby (sleep):

Code: Select all

#!/bin/bash

echo mem > /sys/power/state
2) For hard disk standby (stops spinning):

Code: Select all

#!/bin/bash

notify-send -u critical --expire-time=2500 'OK' 'Putting the disk to sleep...'

sleep 3

hdparm -y /dev/sda
3) For turning off the screen:

Code: Select all

#!/bin/bash

sleep 1

xset dpms force off

I hope it may be useful for somebody else, I'll listen carefully to any comments!

Fabio

Posted: Tue 05 May 2020, 19:44
by enrique
Interesting. I do not have a need, I always shut it off. Puppy and ButserDog in fact boot preaty fast in less than a minute. I can not say same thing for Ubuntu.

But like to test them soon just to have them handy.

Posted: Wed 06 May 2020, 01:42
by nilsonmorales
you can only put one script in the desktop too

Code: Select all

#!/bin/bash 

MEM="echo mem > /sys/power/state"
HDS="hdparm -y /dev/sda"
XSET="xset dpms force off"
yad --title='System Actions' --text='Select a option:' --window-icon=/usr/local/lib/X11/pixmaps/pc48.png --image=gnome-shutdown \
--button="Memory!/usr/local/lib/X11/pixmaps/memory48.png":1 \
--button="HD Standby!/usr/local/lib/X11/pixmaps/drive48.png":2 \
--button="Turn off Screen!/usr/local/lib/X11/pixmaps/shutdown48.png":3

foo=$?
if 
[[ $foo -eq 1 ]]; then
$MEM
fi
if [[ $foo -eq 2 ]]; then
notify-send -u critical --expire-time=2500 "OK" "Putting the disk to sleep..."
sleep 03
$HDS 
fi
if [[ $foo -eq 3 ]]; then
sleep 1
$XSET
fi
Image

Posted: Wed 06 May 2020, 08:05
by Fabio_hw
Thanks nilsonmorales!

Your script not only improves the funcionality (I will also create a keyboard shortcut to it, so to have another option available) but, also, it is an instructive script to me.

For some reason, the pc standby command (MEM variable) does not work for me, but I just saw your comment half an hour ago and I need to understand it in detail (I'm a willing-to-learn Puppy and Bash newbie :wink: ).

So, many thanks and I will try to understand that minor issue!

EDIT:

For a reason that I cannot understand, the YAD script works when the variable MEM is bypassed using the command directly, like this:

Code: Select all

#!/bin/bash

# MEM="echo mem > /sys/power/state"
HDS="hdparm -y /dev/sda"
XSET="xset dpms force off"
yad --title='System Actions' --text='Select a option:' --window-icon=/usr/local/lib/X11/pixmaps/pc48.png --image=gnome-shutdown \
--button="Memory!/usr/local/lib/X11/pixmaps/memory48.png":1 \
--button="HD Standby!/usr/local/lib/X11/pixmaps/drive48.png":2 \
--button="Turn off Screen!/usr/local/lib/X11/pixmaps/shutdown48.png":3

foo=$?
if
[[ $foo -eq 1 ]]; then
echo mem > /sys/power/state          #test
fi
if [[ $foo -eq 2 ]]; then
notify-send -u critical --expire-time=2500 "OK" "Putting the disk to sleep..."
sleep 03
$HDS
fi
if [[ $foo -eq 3 ]]; then
sleep 1
$XSET
fi
------

@enrique

Thanks for your comment! Yes, Puppy reboots quite fast, but I have activated the "save session" option at shutdown (which takes a while), furthermore rebooting implies a read/write cycle on the usb stick (and loss of the current session: LibreOffice work, etc.). Since I normally keep the PC on for several hours a day, I like to have an option to keep everything open and available without rebooting in the case of a longer break. Also, when working with Puppy for several hours, I like to put the disk in standby just to stop it spinning since it will not be used for a long time. But I certainly understand that such preferences depend very much on personal taste and PC typical use!

Posted: Thu 07 May 2020, 06:21
by enrique
But at the same time, longer you leave your PC without powering off. MORE LARGER the cache of your browser. So longer the save it takes!! This browsers save data even when you do not use your PC! I wonder what they are doing...

Posted: Thu 07 May 2020, 08:31
by Fabio_hw
Thanks for your observation, enrique! I agree, the browsers (at least, the most common ones) have now become the hottest single point when it comes to hardware resources (disk, but also RAM, even CPU in some cases...). Especially, as I do with Puppy, running entirely on a usb stick and RAM! Therefore, I need to have some strategies in that regard. I have an extensions (on Firefox) that performs advanced disk storage management (whitelisted sites, etc.) Furthermore, I reduced the cache size to 20 MB (1 GB is recommended...!!) By doing this, I can afford working for hours keeping offline browser data to a minimum!

Posted: Thu 07 May 2020, 10:51
by enrique
Nice info

Can you suggest me where I can read more on "extensions (on Firefox) that performs advanced disk storage management" I personally will love to reduce my "cache size to 20 MB" or what ever best minimum.

Posted: Fri 08 May 2020, 07:37
by Fabio_hw
Sure, enrique!

The extension I use is "Forget me not" for Firefox. It takes a bit to understand the settings but then it does all by itself...

As for cache resizing, I advise the attached tutorial (the question in the tutorial is about increasing the cache size, but the reply applies to the general case of cache resizing - with 20 MB I am not experiencing any problem, although it also depends to some extent on the kind of sites and contents one loads most frequently).

Here are the links:

https://support.mozilla.org/en-US/questions/1272857

https://addons.mozilla.org/en-US/firefo ... et_me_not/

Posted: Fri 08 May 2020, 11:56
by step
Fabio_hw wrote: For a reason that I cannot understand, the YAD script works when the variable MEM is bypassed using the command directly, like this:
That's because I/O redirection symbols inside variables are expanded as literals and not as reserved symbols anymore when bash expands $MEM. Here's an example to clarify my jargon:

Code: Select all

bash-4.4# x="echo hello > /tmp/d"
bash-4.4# $x
hello > /tmp/d
bash-4.4# 
You can see that echo is getting three arguments and printing them all. Therefore, no redirection to /tmp/d ever took place.

Posted: Sat 09 May 2020, 08:35
by Fabio_hw
Thanks for your clarification, step!

Now I see the reason (and thanks for the simple, yet very explanatory example)!