Is there a way to Toggle Lockscreen Screensaver via Keyboard

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Is there a way to Toggle Lockscreen Screensaver via Keyboard

Post by rene »

LittleScriptMan wrote: Tue Apr 12, 2022 3:04 pm On the contrary, I see a will to share knowledge with those interested in.
Thanks for the comment. I was here being a bit overly (and not very seriously...) apologetic but I do in fact tend to dislike people going off on tangents or in alternative directions if/when unnecessary since it can horribly confuse threads, and render previous "work" by other respondents potentially more or less useless. In fact commented on that very issue to someone else not long ago...

Once the thread/original issue is concluded/solved of course anyone -- and thus I -- should feel very free to tangent off in any direction one/I may care for and I thought this one was. Not really yet it seems, but oh well: "sorry but not too much" was just it then :)
Kendoori
Level 5
Level 5
Posts: 748
Joined: Thu Jul 09, 2009 12:51 pm
Location: Sanibel, FL USA

Re: Is there a way to Toggle Lockscreen Screensaver via Keyboard

Post by Kendoori »

In case anyone is still watching this thread, the screensaver lock portion of this is working, but I am finding that the screen will slightly dim after a period of time (no screensaver), but the active application is no longer showing on the screen (it loses focus and just dims). Hitting any key, bring it back to the app. What I'm after here is "always on," even if there is no activity.

Here is the current script, that I added:

Code: Select all

    gsettings set org.cinnamon.settings-daemon.plugins.power sleep-display-ac '14400'
Note that I had set this to 14400, in that I might do a session that lasts this long, but it doesn't not do what I want it to do, nor did "0" in this setting,

Below, is a screenshot of all the org.cinnamon.settings-daemon.plugins.power variables, so perhaps I have chosen the wrong settings. Any tweaks are appreciated.

Code: Select all

#!/bin/bash

# get the current setting of the screensaver lock
lock_enabled=$(gsettings get org.cinnamon.desktop.screensaver lock-enabled)
# if the command failed, abort
[[ $? -eq 0 ]] || exit 1

# if the program was invoked with 'status' argument, just notify user of current status
if [[ $# -eq 1 && $1 = 'status' ]]; then
	if [[ $lock_enabled = 'true' ]]; then
		zenity --notification --text "Screensaver lock is disabled. Jam on!"
	else
		zenity --notification --text "Screensaver lock is enabled."
	fi
	exit
fi

# toggle the screensaver lock, and suspend lock along with it, and notify the user of new status
if [[ $lock_enabled = 'true' ]]; then
	# currently enabled so disable it
	gsettings set org.cinnamon.desktop.screensaver lock-enabled 'false'
	gsettings set org.cinnamon.settings-daemon.plugins.power lock-on-suspend 'false'
    # added to handle display turning off    
    gsettings set org.cinnamon.settings-daemon.plugins.power sleep-display-ac '14400'
	zenity --notification --text "Screensaver lock disabled. Jam on!"
else
	# currently disabled so enable it
	gsettings set org.cinnamon.desktop.screensaver lock-enabled 'true'
	gsettings set org.cinnamon.settings-daemon.plugins.power lock-on-suspend 'true'
    # added to handle display turning off
    gsettings set org.cinnamon.settings-daemon.plugins.power sleep-display-ac '1800'
	zenity --notification --text "Screensaver lock enabled."
fi

Image
Kendoori
Level 5
Level 5
Posts: 748
Joined: Thu Jul 09, 2009 12:51 pm
Location: Sanibel, FL USA

[SOLVED] Re: Is there a way to Toggle Lockscreen Screensaver via Keyboard

Post by Kendoori »

I knew that there was something missing, and it was in a different settings branch. Turns out that I needed to add:

Code: Select all

gsettings set org.cinnamon.desktop.session idle-delay '0'
The revised complete script.

Code: Select all

#!/bin/bash

# get the current setting of the screensaver lock
lock_enabled=$(gsettings get org.cinnamon.desktop.screensaver lock-enabled)
# if the command failed, abort
[[ $? -eq 0 ]] || exit 1

# if the program was invoked with 'status' argument, just notify user of current status
if [[ $# -eq 1 && $1 = 'status' ]]; then
	if [[ $lock_enabled = 'true' ]]; then
		zenity --notification --text "Screensaver lock is disabled. Jam on!"
	else
		zenity --notification --text "Screensaver lock is enabled."
	fi
	exit
fi

# toggle the screensaver lock, and suspend lock along with it, and notify the user of new status
if [[ $lock_enabled = 'true' ]]; then
	# currently enabled so disable it
	gsettings set org.cinnamon.desktop.screensaver lock-enabled 'false'
	gsettings set org.cinnamon.settings-daemon.plugins.power lock-on-suspend 'false'
    # added to handle display turning off    
    gsettings set org.cinnamon.settings-daemon.plugins.power sleep-display-ac '14400'
    gsettings set org.cinnamon.desktop.session idle-delay '0'
	zenity --notification --text "Screensaver lock disabled. Jam on!"
else
	# currently disabled so enable it
	gsettings set org.cinnamon.desktop.screensaver lock-enabled 'true'
	gsettings set org.cinnamon.settings-daemon.plugins.power lock-on-suspend 'true'
    # added to handle display turning off
    gsettings set org.cinnamon.settings-daemon.plugins.power sleep-display-ac '1800'
    gsettings set org.cinnamon.desktop.session idle-delay '1800'
	zenity --notification --text "Screensaver lock enabled."
fi
cmtao2908
Level 1
Level 1
Posts: 1
Joined: Mon Aug 29, 2022 3:12 am

Re: Is there a way to Toggle Lockscreen Screensaver via Keyboard

Post by cmtao2908 »

This worked on the cinnamon desktop for me.

1. Invoke Keyboard application

2. Click on Shortcuts tab

3. From the Categories section (left side of panel), click/select Custom Shortcuts. Then:

+ Click the [ Add custom shortcut ] button (near bottom of panel)

In the "Add custom shortcut" dialog box that appears, do:

        > In the "Name:" textbox, enter 'Lock_Screen'

        > In the "Command:" textbox, enter 'cinnamon-screensaver-command --lock'

    In the Keyboard bindings section, click on an unassigned Keyboard binding and press the new keystroke combination (e.g. Super+ESC)

4. Done
Locked

Return to “Scripts & Bash”