Desktop icons for selective pc standby mode

Using applications, configuring, problems
Post Reply
Message
Author
Fabio_hw
Posts: 12
Joined: Fri 17 Apr 2020, 10:03
Location: Italy
Contact:

Desktop icons for selective pc standby mode

#1 Post 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
Attachments
rsz_desktop_04_05_2020_cropped.png
(168.66 KiB) Downloaded 127 times

enrique
Posts: 595
Joined: Sun 10 Nov 2019, 00:10
Location: Planet Earth

#2 Post 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.

User avatar
nilsonmorales
Posts: 972
Joined: Fri 15 Apr 2011, 14:39
Location: El Salvador

#3 Post 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
[b][url=http://nilsonmorales.blogspot.com/]My blog |[/url][/b][b][url=https://github.com/woofshahenzup]| Github[/url][/b]
[img]https://i.postimg.cc/5tz5vrrX/imag018la6.gif[/img]
[img]http://s5.postimg.org/7h2fid8pz/botones_logos3.png[/img]

Fabio_hw
Posts: 12
Joined: Fri 17 Apr 2020, 10:03
Location: Italy
Contact:

#4 Post 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!

enrique
Posts: 595
Joined: Sun 10 Nov 2019, 00:10
Location: Planet Earth

#5 Post 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...

Fabio_hw
Posts: 12
Joined: Fri 17 Apr 2020, 10:03
Location: Italy
Contact:

#6 Post 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!

enrique
Posts: 595
Joined: Sun 10 Nov 2019, 00:10
Location: Planet Earth

#7 Post 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.

Fabio_hw
Posts: 12
Joined: Fri 17 Apr 2020, 10:03
Location: Italy
Contact:

#8 Post 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/

step
Posts: 1349
Joined: Fri 04 May 2012, 11:20

#9 Post 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.
[url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Fatdog64-810[/url]|[url=http://goo.gl/hqZtiB]+Packages[/url]|[url=http://goo.gl/6dbEzT]Kodi[/url]|[url=http://goo.gl/JQC4Vz]gtkmenuplus[/url]

Fabio_hw
Posts: 12
Joined: Fri 17 Apr 2020, 10:03
Location: Italy
Contact:

#10 Post by Fabio_hw »

Thanks for your clarification, step!

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

Post Reply